Null pointer exception Elasticsearch 2.4.4 with filter and term query

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 & 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

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

thanks!

here the correct query

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

thanks for posting it, looks good to me.

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