Elasticsearch:仅通过搜索查询获取_source字段(不提供文档ID)

时间:2019-05-10 17:49:12

标签: elasticsearch

我有两个文档存储在elasticsearch索引中,

Index: employee

document#1
{
  "name": "praveen"
  "job": "developer"
  "company": "foo"
}

document#2
{
  "name": "joey"
  "job": "manager"
  "company": "bar"
}

要仅获取company字段,我要像这样查询索引

curl -X GET "localhost:9200/employee/_search?pretty&q=name:praveen&filter_path=hits.hits._source.company"

它返回以下内容,

{
  "hits" : {
    "hits" : [
      {
        "_source" : {
          "company" : "foo"
        }
      }
    ]
  }
}

问题:我能否仅获得_source字段的值而没有其他所有内容?这样响应如下所示:

{
  "company": "foo"
}

Elasticsearch中可能吗?

PS:此问题不是Retrieve only _source from elasticsearch的重复,因为我正在使用search api查询整个索引,而不是使用其ID来获取特定文档。

我知道_source端点(在上述问题中使用过)https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#_source,但我认为它仅适用于文档ID,不适用于搜索。

0 个答案:

没有答案
相关问题