# Facet with multiple fields

**URL:** <https://discuss.elastic.co/t/facet-with-multiple-fields/11059>\
**Category:** Elasticsearch\
**Created:** [March 7, 2013, 5:12pm UTC](https://discuss.elastic.co/t/facet-with-multiple-fields/11059 "2013-03-07T17:12:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![matv](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@matv](https://discuss.elastic.co/u/matv)\
**Post date:** [March 7, 2013, 5:12pm UTC](https://discuss.elastic.co/t/facet-with-multiple-fields/11059/1 "2013-03-07T17:12:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:47am UTC](https://discuss.elastic.co/t/facet-with-multiple-fields/11059/2 "2017-07-06T02:47:45Z")

</div>


