Querying data in elastic search

Hi All,

A common issue in elastic search as querying data from ES server. As typical RDBMS server, we can write like

“select * from tablename where columnA is null”

Similarly, if we have to find this data in ES in kibana , then how we can write it

It will be like

GET IndexName/TypeName/_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "object_desc"
}
}
}
}
}

Similarly we can write this in java API ES 2.2 as below

QueryBuilder query = QueryBuilders.boolQuery()
.mustNot(QueryBuilders.existsQuery("object_desc"));

Client client = getClient();
SearchResponse response = client.prepareSearch(indexName)
.setTypes(type)
.setSearchType(SearchType.QUERY_AND_FETCH)
.setQuery(query)
.setFrom(0)
.setSize(10000)
.setExplain(false)
.execute()
.actionGet();
SearchHit[] searchHits = response.getHits().getHits();

ES query API is quite good and you can test in kibana console.

Happy searching with techartifact…