Is there any way how can I create Elasticsearch Search Template from BoolQueryBuilder directly?
up vote
0
down vote
favorite
How can I easily create Search Template from BoolQueryBuilder in Java ?
Right now I am trying to do it like this, but this solution seems a little bit dirty to me. Is there any better way ?
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(new MoreLikeThisQueryBuilder("myField", "myTextToBeReplaced", null));
SearchResponse response = new SearchTemplateRequestBuilder(client)
.setRequest(new SearchRequest())
.setScriptType(ScriptType.INLINE)
.setScript(boolQueryBuilder.toString())
.setScriptParams(templateParams)
.get();
Thank you for any help.
java templates elasticsearch
add a comment |
up vote
0
down vote
favorite
How can I easily create Search Template from BoolQueryBuilder in Java ?
Right now I am trying to do it like this, but this solution seems a little bit dirty to me. Is there any better way ?
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(new MoreLikeThisQueryBuilder("myField", "myTextToBeReplaced", null));
SearchResponse response = new SearchTemplateRequestBuilder(client)
.setRequest(new SearchRequest())
.setScriptType(ScriptType.INLINE)
.setScript(boolQueryBuilder.toString())
.setScriptParams(templateParams)
.get();
Thank you for any help.
java templates elasticsearch
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How can I easily create Search Template from BoolQueryBuilder in Java ?
Right now I am trying to do it like this, but this solution seems a little bit dirty to me. Is there any better way ?
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(new MoreLikeThisQueryBuilder("myField", "myTextToBeReplaced", null));
SearchResponse response = new SearchTemplateRequestBuilder(client)
.setRequest(new SearchRequest())
.setScriptType(ScriptType.INLINE)
.setScript(boolQueryBuilder.toString())
.setScriptParams(templateParams)
.get();
Thank you for any help.
java templates elasticsearch
How can I easily create Search Template from BoolQueryBuilder in Java ?
Right now I am trying to do it like this, but this solution seems a little bit dirty to me. Is there any better way ?
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(new MoreLikeThisQueryBuilder("myField", "myTextToBeReplaced", null));
SearchResponse response = new SearchTemplateRequestBuilder(client)
.setRequest(new SearchRequest())
.setScriptType(ScriptType.INLINE)
.setScript(boolQueryBuilder.toString())
.setScriptParams(templateParams)
.get();
Thank you for any help.
java templates elasticsearch
java templates elasticsearch
asked Nov 10 at 12:34
Druudik
299
299
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You are executing inline templates, and you´re even using boolQueryBuilder.toString() to render the json instead of messy string concatenation. Good work so far @Druudik.
But have you tried stored templates at search time (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) ?
This will move the templating completely out of your java code! Especially for larger queries this approach reduces the code complexity.
This will also make your appliaction more flexible, as you'll be able to change the query/template, without recompiling your code (as long your parameters are stable).
Here are some examples using java api: https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search-template.html
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You are executing inline templates, and you´re even using boolQueryBuilder.toString() to render the json instead of messy string concatenation. Good work so far @Druudik.
But have you tried stored templates at search time (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) ?
This will move the templating completely out of your java code! Especially for larger queries this approach reduces the code complexity.
This will also make your appliaction more flexible, as you'll be able to change the query/template, without recompiling your code (as long your parameters are stable).
Here are some examples using java api: https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search-template.html
add a comment |
up vote
0
down vote
You are executing inline templates, and you´re even using boolQueryBuilder.toString() to render the json instead of messy string concatenation. Good work so far @Druudik.
But have you tried stored templates at search time (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) ?
This will move the templating completely out of your java code! Especially for larger queries this approach reduces the code complexity.
This will also make your appliaction more flexible, as you'll be able to change the query/template, without recompiling your code (as long your parameters are stable).
Here are some examples using java api: https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search-template.html
add a comment |
up vote
0
down vote
up vote
0
down vote
You are executing inline templates, and you´re even using boolQueryBuilder.toString() to render the json instead of messy string concatenation. Good work so far @Druudik.
But have you tried stored templates at search time (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) ?
This will move the templating completely out of your java code! Especially for larger queries this approach reduces the code complexity.
This will also make your appliaction more flexible, as you'll be able to change the query/template, without recompiling your code (as long your parameters are stable).
Here are some examples using java api: https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search-template.html
You are executing inline templates, and you´re even using boolQueryBuilder.toString() to render the json instead of messy string concatenation. Good work so far @Druudik.
But have you tried stored templates at search time (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) ?
This will move the templating completely out of your java code! Especially for larger queries this approach reduces the code complexity.
This will also make your appliaction more flexible, as you'll be able to change the query/template, without recompiling your code (as long your parameters are stable).
Here are some examples using java api: https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search-template.html
answered Nov 10 at 22:06
ibexit
581112
581112
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238995%2fis-there-any-way-how-can-i-create-elasticsearch-search-template-from-boolquerybu%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown