Can anybody please help me to convert the below query to a queryStringQuery which I can execute in java by QueryStringQueryBuilder .
The Query:-
{
"bool" : {
"must" : [
{
"bool" : {
"must" : [
{
"term" : {
"languageId" : {
"value" : "2",
"boost" : 1.0
}
}
},
{
"term" : {
"storeId" : {
"value" : "2",
"boost" : 1.0
}
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"filter" : [
{
"bool" : {
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
{
"bool" : {
"should" : [
{
"range" : {
"publish_date" : {
"from" : "2019-01-26T05:48:27Z",
"to" : null,
"include_lower" : true,
"include_upper" : true,
"boost" : 1.0
}
}
},
{
"bool" : {
"must_not" : [
{
"exists" : {
"field" : "publish_date",
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
{
"bool" : {
"should" : [
{
"range" : {
"publish_end_date" : {
"from" : null,
"to" : "2019-07-26T05:48:27Z",
"include_lower" : true,
"include_upper" : true,
"boost" : 1.0
}
}
},
{
"bool" : {
"must_not" : [
{
"exists" : {
"field" : "publish_end_date",
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"should" : [
{
"bool" : {
"should" : [
{
"match_phrase_prefix" : {
"name" : {
"query" : "spider",
"slop" : 0,
"max_expansions" : 50,
"boost" : 1.0
}
}
},
{
"match_phrase_prefix" : {
"category" : {
"query" : "spider",
"slop" : 0,
"max_expansions" : 50,
"boost" : 1.0
}
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
{
"bool" : {
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
I want to execute this like below-
QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery("The QUERY STRING");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(queryBuilder);
SearchRequest searchRequest = new SearchRequest();
/*****set the indices you want to search in*****/
searchRequest.indices("content","a");
searchRequest.source(searchSourceBuilder);
try {
SearchResponse response = client.search(searchRequest);
System.out.println(response);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}