# Match nested and search another value inside with more data

**URL:** <https://discuss.elastic.co/t/match-nested-and-search-another-value-inside-with-more-data/246743>\
**Category:** Elasticsearch\
**Created:** [August 28, 2020, 10:53am UTC](https://discuss.elastic.co/t/match-nested-and-search-another-value-inside-with-more-data/246743 "2020-08-28T10:53:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkly](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@pkly](https://discuss.elastic.co/u/pkly)\
**Post date:** [August 28, 2020, 10:53am UTC](https://discuss.elastic.co/t/match-nested-and-search-another-value-inside-with-more-data/246743/1 "2020-08-28T10:53:59Z")

</div>

Hi, sorry if you get this question a lot but I don't think my queries are working the way I'd expect them to.  
I have a nested object (let's call it tags) that looks like this:  
`[{"index":"en", "data": "tag_1"}, {"index":"pl", "data": "gat_2"}]`  
My query is something like this

```
{
    "query": {
        "bool": {
            "should": [
                {
                    "simple_query_string": {
                        "query": "gat*",
                        "fields": [
                            "title^2"
                        ]
                    }
                },
                {
                    "bool": {
                        "filter": [
                            {
                                "match": {
                                    "tags.index": {
                                        "query": "en"
                                    }
                                }
                            }
                        ],
                        "must": [
                            {
                                "wildcard": {
                                    "tags.data": {
                                        "value": "gat*"
                                    }
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "from": 0,
    "size": 5,
    "track_total_hits": true
}

```

But I still get results that shouldn't be there, like it's searching through the nested object and doesn't actually look at the "index" field in it at all.  
I've tried doing something similar previously and it was mostly working, but I think it might've just been a fluke.

I'd really appriate some help, thank you in advance.

---

<div class="post-metadata">

**Author:** ![pkly](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@pkly](https://discuss.elastic.co/u/pkly)\
**Post date:** [September 8, 2020, 10:07am UTC](https://discuss.elastic.co/t/match-nested-and-search-another-value-inside-with-more-data/246743/2 "2020-09-08T10:07:46Z")

</div>

I solved it, for anyone having a similar issue: you want to use a nested query and your object needs to be a nested one, so bool inside nested query with path with the name of your object.

---

<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:** [October 6, 2020, 10:07am UTC](https://discuss.elastic.co/t/match-nested-and-search-another-value-inside-with-more-data/246743/3 "2020-10-06T10:07:55Z")

</div>

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