Will ElasticSearch performance differ if we have multiple nested queries

Viewed 161

In general, if we need to do an OR condition in elasticsearch within one nested type, let's say, we do query like below :

Query 1:

{
"query": {
    "bool": {
      "must": [{
        "nested": {
          "query": {
            "bool": {
              "must": [{
                "bool": {
                  "should": [{
                    "match": {
                      "descTags.device": {
                        "query": "abc"
                      }
                    }
                  }, {
                    "match": {
                      "descTags.device": {
                        "query": "xyz"
                      }
                    }
                  }]
                }
              }]
            }
          },
          "path": "descTags"
        }
      }]
    }
  }
}

The above query has one nested and have OR condition within this one nested type.

Representing below the same query with two nested blobs :

Query 2:

{
"query": {
    "bool": {
      "must": [{
        "bool": {
          "should": [{
            "bool": {
              "must": [{
                "nested": {
                  "query": {
                    "bool": {
                      "must": [{
                        "match": {
                          "descTags.Modality": {
                            "query": "abc"
                          }
                        }
                      }]
                    }
                  },
                  "path": "descTags",
                }
              }]
            }
          }, {
            "bool": {
              "must": [{
                "nested": {
                  "query": {
                    "bool": {
                      "must": [{
                        "match": {
                          "descTags.Modality": {
                            "query": "xyz"
                          }
                        }
                      }]
                    }
                  },
                  "path": "descTags"
                }
              }]
            }
          }]
        }
      }]
    }
  }
}

Will there be any difference in performance between query1 and query2 just because we are having nested blob multiple times?

EDIT 1: As per the below comments (@kamal), I am simplifying my question here..

Will there be any difference in performance if the boolean operation is done between "attributes that belong to same nested type, declaring the nested type only once" vs "attributes that belong to same nested type, declaring the nested type twice, once for each attribute".

like below :

1.

nested : 
     or : 
         attribute1
         attribute2

vs

2.

or :
     nested : 
        attribute1
     nested :
        attribute2
0 Answers
Related