I've two documents stored in an elasticsearch index,
Index: employee
document#1
{
"name": "praveen"
"job": "developer"
"company": "foo"
}
document#2
{
"name": "joey"
"job": "manager"
"company": "bar"
}
To fetch just the company
field, I'm querying the index like,
curl -X GET "localhost:9200/employee/_search?pretty&q=name:praveen&filter_path=hits.hits._source.company"
And it returns with following,
{
"hits" : {
"hits" : [
{
"_source" : {
"company" : "foo"
}
}
]
}
}
Question: Can i get just the value of _source
field without everything else? So that the response looks like following,
{
"company": "foo"
}
Is it possible in Elasticsearch?
PS: This question isn't a duplicate of Retrieve only _source from elasticsearch because I am querying the whole index using search
api rather than fetching a particular document using its ID
.
I am aware of _source
endpoint (that is used in above SO question) https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#_source but I think it works only with a document ID
and doesn't work for a search.