# Null\_pointer\_exception

**URL:** <https://discuss.elastic.co/t/null-pointer-exception/218487>\
**Category:** Elasticsearch\
**Created:** [February 9, 2020, 11:22pm UTC](https://discuss.elastic.co/t/null-pointer-exception/218487 "2020-02-09T23:22:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pawelks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawelks/32/62323_2.png) [@pawelks](https://discuss.elastic.co/u/pawelks)\
**Post date:** [February 9, 2020, 11:22pm UTC](https://discuss.elastic.co/t/null-pointer-exception/218487/1 "2020-02-09T23:22:08Z")

</div>

Hello. I'm a newbie in elasticsearch and I have a strange elastic search behaviour. Could someone explain me why belowed query sometimes works and sometimes didnt work? This query should for current date found records. I should mention that in some docs date\_from and date\_to is equal null (it's mean that doc should be also returned) and I don't want to scoring will rely on on this fields. In result I should get random order of docs without scoring on these date fields (randomScore function has a random int as parameter). This query works for some dates and doesn't work for others.

```
{
  "from": 0,
  "size": 12,
  "_source": [   
    "city", "latitude", "description", "title", "id", "lang", "place_id", "longitude", "place_name", "images", "date_to", "subcategory", "date_from", "www"
  ],
  "query": {
    "script_score": {
      "query": {
        "bool": {
          "must": {
            "bool": {
              "must": [
                {
                  "match": {
                    "lang": "pl"
                  }
                },
                {
                  "bool": {
                    "should": [
                      {
                        "bool": {
                          "must_not": {
                            "bool": {
                              "must": [
                                {
                                  "exists": {
                                    "field": "date_to"
                                  }
                                }
                              ]
                            }
                          }
                        }
                      },
                      {
                        "bool": {
                          "must": [
                            {
                              "range": {
                                "date_to": {
                                  "gte": "2020-02-10"
                                }
                              }
                            },
                            {
                              "range": {
                                "date_from": {
                                  "lte": "2020-02-10"
                                }
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        }
      },
      "script": {
        "source": "randomScore(4298)"
       
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 10, 2020, 2:14am UTC](https://discuss.elastic.co/t/null-pointer-exception/218487/2 "2020-02-10T02:14:48Z")

</div>

Welcome!

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

---

<div class="post-metadata">

**Author:** ![rameshkr1994](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rameshkr1994/32/59029_2.png) [@rameshkr1994](https://discuss.elastic.co/u/rameshkr1994)\
**Post date:** [February 10, 2020, 11:28am UTC](https://discuss.elastic.co/t/null-pointer-exception/218487/3 "2020-02-10T11:28:48Z")

</div>

Hi @pawelks.

i think your below query is working sometimes .  
"must": {  
"bool": {  
"must": [  
{  
"match": {  
"lang": "pl"  
}  
},

and rest all code is not taking any responses from your query data.

i think you are only getting output for matched with `"lang": "pl"`

not other than.

correct me if i am wrong here?

Thanks  
HadoopHelp

---

<div class="post-metadata">

**Author:** ![pawelks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawelks/32/62323_2.png) [@pawelks](https://discuss.elastic.co/u/pawelks)\
**Post date:** [February 10, 2020, 12:18pm UTC](https://discuss.elastic.co/t/null-pointer-exception/218487/4 "2020-02-10T12:18:32Z")

</div>

Hi @rameshkr1994. Condition for dates works and ES returns docs that (date\_from\<=now and now\<=date\_to) or (date\_to =null) - it was my intention. And when date is 2020-02-09 - it works and after whena date changes to 2020-02-10 it doesn't work. What's more, when I recently added new docs, dates that did not work before, began to work....

---

<div class="post-metadata">

**Author:** ![rameshkr1994](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rameshkr1994/32/59029_2.png) [@rameshkr1994](https://discuss.elastic.co/u/rameshkr1994)\
**Post date:** [February 10, 2020, 12:31pm UTC](https://discuss.elastic.co/t/null-pointer-exception/218487/5 "2020-02-10T12:31:07Z")

</div>

> [@pawelks](#):
>
> "date\_from": { "lte": "2020-02-10" }

Ok @pawelks.

so problem here is you are bale to combine both matched for `"lang":"pl" and "date":"Your date" `

is that correct ?

if yes then you can't perform two must condition in single query.

you can also verify that by using separate must query.it will work ?but combining both in single it may not work?

please check and confirm me?i faced the issue while implemented same POC.as below-

[may help you](https://discuss.elastic.co/t/elastic-search-advanced-search-query-issue/198254/9)

Thanks  
HadoopHelp

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 9, 2020, 12:31pm UTC](https://discuss.elastic.co/t/null-pointer-exception/218487/6 "2020-03-09T12:31:12Z")

</div>

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