每个searchRequest.toString()
和每个错误信息。
我认为,如果您在检查那些搜索内容和错误之前在底部看到摘要,应该更容易理解我的问题。
搜索身体
{
"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" : { }
}
}
}
错误:
QueryParsingException[[hy_index] [bool] query does not support [must]];
搜索身体
{
"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" : { }
}
}
}
错误
QueryParsingException[[hy_index] [bool] query does not support [should]]
搜索身体
{
"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" : { }
}
}
}
错误
QueryParsingException[[hy_index] [_na] query malformed, must start with start_object];
搜索身体
{
"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" : { }
}
}
}
这没有错误。
现在,总结。
不管我用should
或must
在"term" : {"2474" : [ "20", "17" ]}
。
当我"term" : {"2474" : [ "20", "17" ]}
在查询正文中设置时,它总是会出错。
一旦我"term" : {"2474" : [ "20", "17" ]}
从查询主体中删除,它就可以正常工作。
为什么?
字词查询只需要一个值。术语意味着一个以上的价值。请尝试一下
"terms" : {"2474" : [ "20", "17" ]}
将术语查询更改为术语。请参考以下网址,http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句