为什么此查询给我一个解析异常?如果我把它移开,它似乎确实起作用。但是我需要在其中带有query_string的布尔值。我该如何工作?
{ "query": { "filtered": { "query": { "bool": { "must": [ { "terms": { "status_type": [ "5" ] } } ] } }, "filter": { "query_string": { "fields": [ [ "name", "message" ] ], "query": "Arnold AND Schwarz" } } } }, "sort": [ { "total_metrics": { "order": "desc" } } ] }
您应该使用查询过滤器,它将所有查询包装到过滤器中。否则,您将得到解析错误No filter registered for [query_string]。
No filter registered for [query_string]
您需要将filter零件更改为:
filter
"filter": { "query": { // <- wraps a query as a filter "query_string": { "fields": [ [ "name", "message" ] ], "query": "Arnold AND Schwarz" } } }
@Edit:由于我看到人们可能会注意到,我只粘贴了整个查询的更改部分,包括filter部分(而不是整个filtered),所以这里是修改后的全部:
filtered
{ "query": { "filtered": { "query": { "bool": { "must": [ { "terms": { "status_type": [ "5" ] } } ] } }, "filter": { "query": { // <- the only difference! "query_string": { "fields": [ [ "name", "message" ] ], "query": "Arnold AND Schwarz" } } } } }, "sort": [ { "total_metrics": { "order": "desc" } } ] }