Amit's Garage

A garage where one can get tools to solve their problems

Search records in elasticsearch with empty fields OR no values

December 13, 2017 by BlakDronzer

PROBLEM

There are times and situations when in elasticsearch, while inserting, we don’t set any value at that moment. It is quite possible, we don’t have the value yet set. Like say, we are inserting in some article but at that point of time, we don’t have value to be set for sentiment at the time of insertion. Then the value dose not get set in the document that is indexed. If we see the document, we won’t find the key there even if we have mapped it.

SOLUTION

Now, if we were to find such articles who such keys missing, we can trace the same using scripting

 


GET articles
{
	"from": 0,
	"size": 200,
	"query": {
		"bool": {
			"must": {
				"script": {
					"script": {
						"inline": "doc[\"sentiment\"].empty"
					}
				}
			}
		}
	}
}

OR the same can also be simplified with the new Elasticsearch-SQL


GET _sql?sql=Select * from articles where script('doc["sentiment"].empty')
 This way we can get all the records whose values have not been set yet.

Share :  

2751   BlakDronzer    Elastic Search  
Total 0 Votes:
0
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Related Knowledge Base Posts -

  • Why should we map an index in elasticsearch
  • Install and create a cluster of ES Servers
  • Updating data in Elasticsearch
  • Search Knowledgebase