每个 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" : { }
}
}
}
这个没有错误。
现在,总结。
无论我在 "term": {"2474": [ "20", "17"]}
处使用 should
还是 must
。
当我在查询正文中设置 "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
关于java - ElasticSearch Java API 搜索错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23579302/