Must_not nested with should query not working (ES version 7.10.2) -- not countryiso OR not branch_id

{
  "size": 0,
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "is_reachable": {
              "value": "YES",
              "boost": 1
            }
          }
        },
        {
          "exists": {
            "field": "user_id",
            "boost": 1
          }
        },
        {
          "terms": {
            "account_type": [
              "LEAD"
            ],
            "boost": 1
          }
        }
      ],
      "must_not": [
        {
          "exists": {
            "field": "customer_on",
            "boost": 1
          }
        },
        {
          "nested": {
            "query": {
              "bool": {
                "filter": [
                  {
                    "bool": {
                      "should": [
                        {
                          "terms": {
                            "customer_business_relations.country_iso": [
                              "AE"
                            ],
                            "boost": 1
                          }
                        },
                        {
                          "terms": {
                            "customer_business_relations.branch_id": [
                              11385
                            ],
                            "boost": 1
                          }
                        }
                      ],
                      "adjust_pure_negative": true,
                      "boost": 1
                    }
                  },
                  {
                    "terms": {
                      "customer_business_relations.account_type": [
                        "LEAD"
                      ],
                      "boost": 1
                    }
                  }
                ],
                "adjust_pure_negative": true,
                "boost": 1
              }
            },
            "path": "customer_business_relations",
            "ignore_unmapped": false,
            "score_mode": "none",
            "boost": 1
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "aggregations": {
    "ACCOUNT_TYPE": {
      "terms": {
        "field": "account_type",
        "size": 5,
        "min_doc_count": 1,
        "shard_min_doc_count": 0,
        "show_term_doc_count_error": false,
        "order": [
          {
            "_count": "desc"
          },
          {
            "_key": "asc"
          }
        ]
      }
    },
    "PHONE": {
      "filter": {
        "term": {
          "has_phone": {
            "value": "true",
            "boost": 1
          }
        }
      }
    },
    "REACHABLE_PHONES": {
      "filter": {
        "term": {
          "is_phone_reachable": {
            "value": "true",
            "boost": 1
          }
        }
      }
    },
    "EMAIL": {
      "filter": {
        "term": {
          "has_email": {
            "value": "true",
            "boost": 1
          }
        }
      }
    },
    "REACHABLE_EMAILS": {
      "filter": {
        "term": {
          "is_email_reachable": {
            "value": "true",
            "boost": 1
          }
        }
      }
    },
    "UNDELIVERED_NESTED_MAPPINGS": {
      "nested": {
        "path": "undelivered_communications"
      },
      "aggregations": {
        "UNDELIVERED_COMMUNICATION": {
          "terms": {
            "field": "undelivered_communications.channel",
            "size": 5,
            "min_doc_count": 1,
            "shard_min_doc_count": 0,
            "show_term_doc_count_error": false,
            "order": [
              {
                "_count": "desc"
              },
              {
                "_key": "asc"
              }
            ]
          }
        }
      }
    }
  }
}


in the must_not part i have two condition inside should . if any one condition true count must be increased .but count is not getting increased

You have a big query, so I am posting the relavant part, I hope you are talking about following part of your query.

         {
                                                    "terms":
                                                    {
                                                        "customer_business_relations.country_iso":
                                                        [
                                                            "AE"
                                                        ],
                                                        "boost": 1
                                                    }
                                                },
                                                {
                                                    "terms":
                                                    {
                                                        "customer_business_relations.branch_id":
                                                        [
                                                            11385
                                                        ],
                                                        "boost": 1
                                                    }
                                                }

If yes, can you explain what do you mean by count not increasing? do you mean the no of search hit, returned by Elasticsearch ?

yes,this is the part,count means the aggregation will return doc_count .example
image

if any one condition true need to increase the count

this is the condition (must_not country_iso) OR (must_not branch_id)

Thanks @Udayaprakash_S_10d , but you are writing these two conditions, which are enclosed by the must_not clause, so instead of increasing the count, it will decrease the count, if it matches the condition. Hope this helps.

yes correct .i put that two condition inside must_not,if i create one user with "AE" ="country_iso" ( condition false) and different "branchid" (condition true) so the second condition is true so,i need to increase the count. but the count remain same

my query condition must_not( (country_iso = "AE) OR (branch_id = 11385) )

so ,if i create one user with country_iso = "AE" (false) ,
branch_id = 11200 (true)

so the second condition is true ,thats why i need to increase the count

Thanks for example, it makes sense, can you also provide the mapping of your index, I see you are using the nested query but missing the path param in the query, can you add it in the request as explained in the document , and test again?

image
mapping

also tested with path param
image
getting error
image

Sorry, my bad, I see you already defined that in your old query, and error message is clearly indicating it, you can remove it.

any help regarding this condition

my query condition must_not( (country_iso = "AE) OR (branch_id = 11385) )

so ,if i create one user with country_iso = "AE" (false) ,
branch_id = 11200 (true)

so the second condition is true , need to increase the count

i have two condition in must_not with OR condition .need to compare that two condition in every document if any one condition true need that response in doc_count

but now ,what happens----> if the user country_iso = "AE" the must_not removed the doc related the country condition , so the next condition is not getting compared, because the country condition is removed the doc in response

the main logic which I want is , both the condition are need to be compared simultaneously in the doc

please help

Welcome to our community @Udayaprakash_S_10d! :smiley:

Please format your code/logs/config using the </> button, or markdown style back ticks. It helps to make things easy to read which helps us help you. Also don't post pictures of text, logs or code. They are difficult to read, impossible to search and replicate (if it's code), and some people may not be even able to see them :slight_smile:

sure

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