【问题标题】:How can I include query string in elastic search response如何在弹性搜索响应中包含查询字符串
【发布时间】:2020-09-05 01:50:05
【问题描述】:

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

【问题讨论】:

标签: elasticsearch


【解决方案1】:

您可以使用named queries。您可以为将出现在结果中的每个查询分配一个名称

查询:

{
  "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

【讨论】:

  • 这适用于 curl。但是我需要一个浏览器 URL。可能吗 ?例如,localshostt/_search?pretty=true&q=cityname:chicago&_name:chicago
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    相关资源
    最近更新 更多