Reputation: 3581
The each searchRequest.toString()
and each error info.
I think if you see the summary at bottom before check those search body and error, should be more easy to understand my problem.
SEARCH BODY
{
"from" : 0,
"size" : 12,
"query" : {
"custom_filters_score" : {
"query" : {
"bool" : {
"must" : {
"term" : {
"2474" : [ "20", "17" ]
}
},
"should" : {
"term" : {
"productName" : {
"value" : "xxx",
"boost" : 3.0
}
}
}
}
},
"filters" : [ {
"filter" : {
"terms" : {
"availableStock" : [ 0 ]
}
},
"boost" : -10.0
} ]
}
},
"filter" : {
"bool" : {
"must_not" : {
"term" : {
"ecPrice" : -1
}
}
}
},
"sort" : [ {
"_score" : {
"order" : "desc"
}
} ],
"facets" : {
"productBrandName" : {
"terms" : {
"field" : "productBrandName",
"size" : 10
}
}
},
"highlight" : {
"pre_tags" : [ "<font style='color:red'>" ],
"post_tags" : [ "</font>" ],
"fields" : {
"productName" : { },
"drugTreatment" : { }
}
}
}
ERROR:
QueryParsingException[[hy_index] [bool] query does not support [must]];
SEARCH BODY
{
"from" : 0,
"size" : 12,
"query" : {
"custom_filters_score" : {
"query" : {
"bool" : {
"should" : {
"term" : {
"2474" : [ "20", "17" ]
}
}
}
},
"filters" : [ ]
}
},
"filter" : {
"bool" : {
"must_not" : {
"term" : {
"ecPrice" : -1
}
}
}
},
"sort" : [ {
"_score" : {
"order" : "desc"
}
} ],
"facets" : {
"productBrandName" : {
"terms" : {
"field" : "productBrandName",
"size" : 10
}
}
},
"highlight" : {
"pre_tags" : [ "<font style='color:red'>" ],
"post_tags" : [ "</font>" ],
"fields" : {
"productName" : { },
"drugTreatment" : { }
}
}
}
ERROR
QueryParsingException[[hy_index] [bool] query does not support [should]]
SEARCH BODY
{
"from" : 0,
"size" : 12,
"query" : {
"custom_filters_score" : {
"query" : {
"bool" : {
"should" : [ {
"term" : {
"productName" : {
"value" : "xxx",
"boost" : 3.0
}
}
}, {
"term" : {
"2474" : [ "20", "17" ]
}
} ]
}
},
"filters" : [ {
"filter" : {
"terms" : {
"availableStock" : [ 0 ]
}
},
"boost" : -10.0
} ]
}
},
"filter" : {
"bool" : {
"must_not" : {
"term" : {
"ecPrice" : -1
}
}
}
},
"sort" : [ {
"_score" : {
"order" : "desc"
}
} ],
"facets" : {
"productBrandName" : {
"terms" : {
"field" : "productBrandName",
"size" : 10
}
}
},
"highlight" : {
"pre_tags" : [ "<font style='color:red'>" ],
"post_tags" : [ "</font>" ],
"fields" : {
"productName" : { },
"drugTreatment" : { }
}
}
}
ERROR
QueryParsingException[[hy_index] [_na] query malformed, must start with start_object];
SEARCH BODY
{
"from" : 0,
"size" : 12,
"query" : {
"custom_filters_score" : {
"query" : {
"bool" : {
"should" : {
"term" : {
"productName" : {
"value" : "撒",
"boost" : 3.0
}
}
}
}
},
"filters" : [ {
"filter" : {
"terms" : {
"availableStock" : [ 0 ]
}
},
"boost" : -10.0
} ]
}
},
"filter" : {
"bool" : {
"must_not" : {
"term" : {
"ecPrice" : -1
}
}
}
},
"sort" : [ {
"_score" : {
"order" : "desc"
}
} ],
"facets" : {
"productBrandName" : {
"terms" : {
"field" : "productBrandName",
"size" : 10
}
}
},
"highlight" : {
"pre_tags" : [ "<font style='color:red'>" ],
"post_tags" : [ "</font>" ],
"fields" : {
"productName" : { },
"drugTreatment" : { }
}
}
}
This one has no error.
Now, Summary.
No matter I use should
or must
at "term" : {"2474" : [ "20", "17" ]}
.
It always get error when I set "term" : {"2474" : [ "20", "17" ]}
in query body.
Once I remove "term" : {"2474" : [ "20", "17" ]}
from query body, it works fine.
Why?
Upvotes: 1
Views: 697
Reputation: 5747
Term query expect only one value. Terms mean more than one value.. Try lik this
"terms" : {"2474" : [ "20", "17" ]}
Change term query to terms.. Refer following url ,http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html
Upvotes: 1