Elastic search match query over array object

Suppose i've 3 doc

doc_1 = {
    "citedIn": [
        "Bar Councils Act, 1926 - Section 15",
        "Contract Act, 1872 - Section 23"
    ]
}

doc_2 = {
    "citedIn":[
        "15 C. B 400", 
        "Contract Act, 1872 - Section 55"
    ]
}

doc_3 = {
    "citedIn":[
        "15 C. B 400", 
        "Contract Act, 1872 - Section 15"
    ]
}

Here citedIn field is a array object.Now i want run a stander match query

{
    "query":
    {
        "match": {"citedIn":{"query": "Contract act 15" , "operator":"and" }}
    }

}

The above query return all of the 3 doc, but it suppose to return doc_3 as only doc_3 contain Contract, act and 15 together in a single array element .

i also did try nested field.
This Is my mapping

{
    "mappings": {
        "properties": {
            "citedIn": {
                "type": "nested",
                "include_in_parent": true,
                "properties": {
                    "someFiled": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    }
                }
            }
        }
    }
}

This is my data

doc_1 = {
    "citedIn": [
        {"someFiled" : "Bar Councils Act, 1926 - Section 15"},
        {"someFiled" : "Contract Act, 1872 - Section 23"}
    ]
}

doc_2 = {
    "citedIn":[
        {"someFiled" : "15 C. B 400"}
        {"someFiled" : "Contract Act, 1872 - Section 55"}
    ]
}

doc_3 = {
    "citedIn":[
        {"someFiled" : "15 C. B 400"},
        {"someFiled" : "Contract Act, 1872 - Section 15"}
    ]
}

This is my query

{
    "query":
    {

        "match": {"citedIn.someFiled":{"query": "Contract act 15" , "operator":"and" }}
            
        
    }
}

But still getting same result .

How would i achieve this ?

Any suggestion/Solution would be preferable

Hey,

you also need to wrap the match query within a nested query. See https://www.elastic.co/guide/en/elasticsearch/reference/7.9/query-dsl-nested-query.html - not sure if you did this.

Also, please a provide a fully reproducible example, that others can copy&paste into the kibana dev tools console. It's easier to test than incomplete snippets of programming languages... THanks!

Solved the issue wth Nested Query

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