elasticsearch获取匹配值的所有键

hlswsv35  于 2023-02-21  发布在  ElasticSearch
关注(0)|答案(1)|浏览(135)

嗨,我是ElasticSearch的新手,
如何从索引文档中获取与查询匹配的所有键?
ElasticSearch中的示例文档:

{
 testKey1:"The quick brown fox",
 testKey2:"The quck",
 testKey3:"The",
 testKey4:"fox"
 }

如果我在索引中搜索“fox”,我需要得到:

{
  testKey1:"The quick brown fox",
  testKey4:"fox"
  }

拜托,给点建议?

baubqpgj

baubqpgj1#

我认为您需要使用Multi Match Query .使用_source来选择要返回结果的字段。

{
  "_source": [
    "testKey1",
    "testKey4"
  ],
  "query": {
    "multi_match": {
      "query": "fox",
      "fields": [
        "testKey1",
        "testKey2",
        "testKey3",
        "testKey4"
      ]
    }
  }
}

相关问题