# Null pointer exception Elasticsearch 2.4.4 with filter and term query

**URL:** <https://discuss.elastic.co/t/null-pointer-exception-elasticsearch-2-4-4-with-filter-and-term-query/76036>\
**Category:** Elasticsearch\
**Created:** [February 22, 2017, 12:57pm UTC](https://discuss.elastic.co/t/null-pointer-exception-elasticsearch-2-4-4-with-filter-and-term-query/76036 "2017-02-22T12:57:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Infrid](https://avatars.discourse-cdn.com/v4/letter/i/db5fbb/32.png) [@Infrid](https://discuss.elastic.co/u/Infrid)\
**Post date:** [February 22, 2017, 12:57pm UTC](https://discuss.elastic.co/t/null-pointer-exception-elasticsearch-2-4-4-with-filter-and-term-query/76036/1 "2017-02-22T12:57:41Z")

</div>

Hello,  
I am trying to filter results from a query using multiple _term_ but I get a _null pointer exception_, the query fails even with an empty index. Does the query looks ok?

I am using Elasticsearch 2.4.4 and Oracle Java 8 ( 8u121 )

Thanks

## Mapping

```
{
    "mappings": {
        "articles": {
            "_all": {
                "enabled": false
            }, 
            "dynamic": "false", 
            "properties": {
		"post_status": {
		    "doc_values": false, 
		    "index": "not_analyzed", 
		    "type": "string"
		},
		"company": {
		    "index": "not_analyzed", 
		    "term_vector": "yes", 
		    "type": "string"
		}
	    }
	}
    }
}

```

## Query

```
{
  "query": {
    "bool": {
      "filter": {
        "term": [
          {
            "company": "Aluko &amp; Oyebode"
          },
          {
            "post_status": "publish"
          }
        ]
      }
    }
  }
}

```

## Result

```
{
    "error": {
        "failed_shards": [
            {
                "index": "myindex", 
                "node": "On0Zwx6fSCGDQ09oomcfuw", 
                "reason": {
                    "reason": null, 
                    "type": "null_pointer_exception"
                }, 
                "shard": 0
            }
        ], 
        "grouped": true, 
        "phase": "query", 
        "reason": "all shards failed", 
        "root_cause": [
            {
                "reason": null, 
                "type": "null_pointer_exception"
            }
        ], 
        "type": "search_phase_execution_exception"
    }, 
    "status": 500
}

```

## log

(too long to be included here)

[http://pastebin.com/BtTkhycf](http://pastebin.com/BtTkhycf)

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [February 22, 2017, 3:49pm UTC](https://discuss.elastic.co/t/null-pointer-exception-elasticsearch-2-4-4-with-filter-and-term-query/76036/2 "2017-02-22T15:49:39Z")

</div>

hi,  
the stacktrace is a bit unfortunate, but your query is malformed. Term query doesn't accept an array, it has to be an object. If you want to have two term queries against one field each, you need to make filter an array and have two term objects within it.

I am pretty sure we made this error clearer in 5.x.

Cheers  
Luca

---

<div class="post-metadata">

**Author:** ![Infrid](https://avatars.discourse-cdn.com/v4/letter/i/db5fbb/32.png) [@Infrid](https://discuss.elastic.co/u/Infrid)\
**Post date:** [February 22, 2017, 4:18pm UTC](https://discuss.elastic.co/t/null-pointer-exception-elasticsearch-2-4-4-with-filter-and-term-query/76036/3 "2017-02-22T16:18:37Z")

</div>

thanks!

here the correct query

```
{
    "query": {
        "bool": {
            "filter":[
		{
		    "term": {
			"company":"test123"
		    }
		},
		{
		    "term":{
			"post_status": "publish"
		    }
		}
	    ]
	}
    }
}
```

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [February 22, 2017, 4:19pm UTC](https://discuss.elastic.co/t/null-pointer-exception-elasticsearch-2-4-4-with-filter-and-term-query/76036/4 "2017-02-22T16:19:39Z")

</div>

thanks for posting it, looks good to me.

---

<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 22, 2017, 4:19pm UTC](https://discuss.elastic.co/t/null-pointer-exception-elasticsearch-2-4-4-with-filter-and-term-query/76036/5 "2017-03-22T16:19:48Z")

</div>

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