我有两个文档存储在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
,不适用于搜索。