# Nested document full text query with filter capability

**URL:** <https://discuss.elastic.co/t/nested-document-full-text-query-with-filter-capability/317843>\
**Category:** Elasticsearch\
**Created:** [October 31, 2022, 6:49pm UTC](https://discuss.elastic.co/t/nested-document-full-text-query-with-filter-capability/317843 "2022-10-31T18:49:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![john2022](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@john2022](https://discuss.elastic.co/u/john2022)\
**Post date:** [October 31, 2022, 6:49pm UTC](https://discuss.elastic.co/t/nested-document-full-text-query-with-filter-capability/317843/1 "2022-10-31T18:49:45Z")

</div>

Hi dear  
My index mappings and sample data as follows

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/3/f3b36618311260352714473d3cb95b2eb88f6032.png)

I need full text search on these type of documents with following criteria:

1. country is one input of this search

2. If I search "Alex 4455" and country is "xxx" this document will be matched and return following document.

3. If I search "Landing" and country is "xxx" this document will be matched and return following document.  

4. If I search "Martin 4455" and country is "xxx", result is null.

In the other hand, I need combined\_field in nested document with filter capability!!!

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [November 1, 2022, 10:22am UTC](https://discuss.elastic.co/t/nested-document-full-text-query-with-filter-capability/317843/2 "2022-11-01T10:22:16Z")

</div>

Hi John,

Welcome to the community! For next time please include your mapping as code rather than images as it makes it easier to read and copy.

It looks like you will need a nested query to search this structure, and to get the member criteria that matches you'll want to use inner\_hits:

> **[Nested query | Elasticsearch Guide \[8.4\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.4/query-dsl-nested-query.html)**

> **[Retrieve inner hits | Elasticsearch Guide \[8.4\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/inner-hits.html)**

An example to get you started and see what the response is like would be something like the below. You'll see that within inner\_hits in the response the matching members in the nested structure are returned.

```auto
GET manager/_search
{
  "query": {
    "nested": {
      "path": "member",
      "query": {
        "bool": {
          "must": [
            { "match": {
              "member.address": "Landing"
              }
            },
            {
              "match": {
                "member.country": "xxx"
              }
            }
          ]
        }
      },
      "inner_hits": {
      }
    }
  }
}

```

---

<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:** [November 29, 2022, 10:23am UTC](https://discuss.elastic.co/t/nested-document-full-text-query-with-filter-capability/317843/3 "2022-11-29T10:23:12Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
