Match nested and search another value inside with more data

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.

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.

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