如何在弹性搜索响应中包含查询字符串



前端正在向弹性服务器发送异步调用。为了匹配响应,我想在弹性响应 json 中添加查询字符串。 弹性搜索是否有任何选项可以在响应中包含查询字符串?

可以使用命名查询。您可以为每个查询分配一个名称,该名称将显示在结果中

查询:

{
"query": {
"query_string": {
"query": "this OR thus",
"_name":"query1"
}
}
}

结果:

"hits" : [
{
"_index" : "index50",
"_type" : "_doc",
"_id" : "VDBsK3IBpnSikKlzkKY3",
"_score" : 0.2876821,
"_source" : {
"name" : "this"
},
"matched_queries" : [
"query1"    ---> name passed in query
]
}
]

要在网址中搜索:

localhost:9200/_search?pretty&source={"query": {"query_string": {
"query": "this OR thus", "_name":"query1"} }}
&source_content_type=application/json

无论如何,文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html 都没有提到它。

我认为这样的选项不存在,因为存在几种类型的查询,并且对于其中大多数,不仅仅是查询字符串。

最新更新