0

I have a "date_created_tranx" and "phone_number_cust" fields. Few entries of date_created_tranx are null . I want to have particular phone_number within date_range and with null value.

a = {
    "query": {
        "bool": {
            "must": [
                {
                    "range": {
                        "date_created_tranx": {
                            "gte": "2019-12-01",
                            "lte": "2020-05-07"
                        }
                    }
                },
                {
                    "regexp": {
                        "phone_number_cust": ".*702625.*"
                    }
                }
            ]
        }
    }
 }


b  = {
    "query": {
        "bool": {
            "must": [{
                "regexp": {
                    "phone_number_cust": ".*702625.*"
                }
            }],
            "must_not": [{
                    "exists": {
                        "field": "date_created_tranx"
                    }
                }
            ]
        }
    }
}

How to combine these ?? I cannot call it twice because The result is paginated I am totally new to elastic search . Any leads will be helpful. I tried

doc2 =   { 
    "query" :{
        "bool" : {
            "must":[
                a,
                b
            ]
        }
    }

}

It throws
Error:  RequestError: RequestError(400, 'parsing_exception', 'no [query] registered for [query]')

1 Answer 1

1

The query you're looking for is this one, i.e.:

We have a constraint on the phone number and we also check that either the date_created_tranx is within bounds or does not exist (i.e. is null).

{
  "query": {
    "bool": {
      "minimum_should_match": 1,
      "should": [
        {
          "range": {
            "date_created_tranx": {
              "gte": "2019-12-01",
              "lte": "2020-05-07"
            }
          }
        },
        {
          "bool": {
            "must_not": {
              "exists": {
                "field": "date_created_tranx"
              }
            }
          }
        }
      ],
      "filter": [
        {
          "regexp": {
            "phone_number_cust": ".*702625.*"
          }
        }
      ]
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.