I have following index:
curl -XPUT "http://localhost:9200/test/" -d ' { "mappings": { "files": { "properties": { "name": { "type": "string", "index": "not_analyzed" }, "owners": { "type": "nested", "properties": { "name": { "type":"string", "index":"not_analyzed" }, "mail": { "type":"string", "index":"not_analyzed" } } } } } } } '
With sample documents:
curl -XPUT "http://localhost:9200/test/files/1" -d ' { "name": "first.jpg", "owners": [ { "name": "John Smith", "mail": "js@example.com" }, { "name": "Joe Smith", "mail": "joes@example.com" } ] } ' curl -XPUT "http://localhost:9200/test/files/2" -d ' { "name": "second.jpg", "owners": [ { "name": "John Smith", "mail": "js@example.com" }, { "name": "Ann Smith", "mail": "as@example.com" } ] } ' curl -XPUT "http://localhost:9200/test/files/3" -d ' { "name": "third.jpg", "owners": [ { "name": "Kate Foo", "mail": "kf@example.com" } ] } '
And I need to find all owners that match some query, let's say "mit":
curl -XGET "http://localhost:9200/test/files/_search" -d ' { "facets": { "owners": { "terms": { "field": "owners.name" }, "facet_filter": { "query": { "query_string": { "query": "*mit*", "default_field": "owners.name" } } }, "nested": "owners" } } } '
This gives me following result:
{ "facets" : { "owners" : { "missing" : 0, "_type" : "terms", "other" : 0, "total" : 4, "terms" : [ { "count" : 2, "term" : "John Smith" }, { "count" : 1, "term" : "Joe Smith" }, { "count" : 1, "term" : "Ann Smith" } ] } }, "timed_out" : false, "hits" : {...} }
And it's ok.
But what I exaclty need is to get owners with their email addresses (for each facet I need additional field in results).
Is it possible to achive?