Home > OS >  Can we suppress nested type object in ES on query time
Can we suppress nested type object in ES on query time

Time:05-11

abcInfo column is of type = nested and is indexed in ES.

abcInfo = 
[
    {
        "number": "1",
        "status": "Yes"
    },  
    {
        "number": "2",
        "status": "No"
    },
    ...
]

Query Used:

{
    "nested": {
        "score_mode": "max",
        "path": "abcInfo",
        "query": {
            "bool": {
                "filter": [
                    {'term': {'abcInfo.number.keyword' : number}},
                    {'term': {'abcInfo.status.keyword' : status}}
                ]
            }
        }
    }
}

Ideal usage of type=nested for below results

number  status  result
1       Yes     Got
1       No      -
2       Yes     -
2       No      Got
  • Now comes the interesting part and which is my question
  • Whilst querying, I want to tell ES forcefully not to treat this as nested type list
  • Rather, what I want to accomplish is number should match one object and status should match from another object within the same list abcInfo [this is nested type as mentioned earlier]
  • How do I suppress it at query time when needed, [as I want to be able to query for both kind of scenarios explained here]
  • Below is the result which I want and how it looks like
number  status  result
1       Yes     -
1       No      Got
2       Yes     Got
2       No      -

CodePudding user response:

Index your content as nested and non-nested in two fields. You cannot control the behavior of a nested object in runtime.

  • Related