How to retrieve all the documents in which specified field has value?

Solr provides this feature .

field : [ * TO * ] matches all documents with the field

(from solr wiki http://wiki.apache.org/solr/SolrQuerySyntax)

Sorry, what's the question? If Elasticsearch supports the [x TO y] range query operation? If yes, see http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-query-string-query.html#_ranges_2. If no, please clarify your question.

Lets say my documents have the following fields 1.id 2.name 3.country

Example documents
doc1 : {"id" : 1 , "name": "name1" , "country": "india"}
doc2 : {"id" : 2 , "name": "name2" }
doc3 : {"id" : 3 , "name": "name3" , "country": "UK"}
doc4 : {"id" : 4 , "name": "name4" }

In solr , if i give country : [ * TO * ] , i will get document doc1 & doc3 .

I mean , field : [ * TO * ] will give documents in which it has values for the requested field.

You could use exists filter?

http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html

1 Like

+1 to David's suggestion. Note that using exists would also be potentially MUCH faster than a range query by using the special _field_names field: http://www.elastic.co/guide/en/elasticsearch/reference/1.x/mapping-field-names-field.html

Thanks for the suggestion David . 'exists' filter worked nicely .
Btw, field : [ * To * ] also worked . Sorry for the wrong reporting .
In our indexing code protobuffer to json conversion part has been modified , where we are started adding empty string for fields which doesn't have value.

@jpountz We will use exists filter , thanks for the suggestion !