Return field where text was found in ElasticSearch
I assume that by key you mean the document ID.
When indexing the following documents:
PUT my_index/my_type/1{ "name":"Sam", "age":25, "description":"Something"}PUT my_index/my_type/2{ "name":"Michael", "age":23, "description":"Something else"}
And searching for:
GET /my_index/my_type/_search?q=Michael
You'll get the following response:
{ "took": 8, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 0.15342641, "hits": [ { "_index": "my_index", "_type": "my_type", "_id": "2", "_score": 0.15342641, "_source": { "name": "Michael", "age": 23, "description": "Something else" } } ] }}
As you can see, the hits array contains an object for each search hit.
The key for Michael in this case is "_id": "2" which its his document id.
Hope it helps.