views:

30

answers:

1

I want to find all documents in the index that have a certain field, regardless of the field's value. If at all possible using the query language, not the API.

Is there a way?

+1  A: 

If you know the type of data stored in your field, you can try a range query. Per example, if your field contain string data, a query like field:[a* TO z*] would return all documents where there is a string value in that field.

Pascal Dimassimo
This should work. It would be slightly more complex in case the field has values starting with numbers or capital letters. Should be easy to do with an OR query.
Shashikant Kore
Good point! But if it starts with a capital, a range starting with a* should catch it because the javadoc of TermRangeQuery states that it uses String.compareTo to determine if a string is part of the range.
Pascal Dimassimo
This looks good. Not sure about catching records starting with numbers, but this is a good start. Thanks!
Buddy Casino
The lexicographic order of strings defines numbers before letters so a range [0* TO z*] would catch all values starting by both letters and numbers. And capital letters appears before lower-case (in contrary to what I have said in my previous comment). Don't forget to check how your values are indexed: they may be all lower-cased!
Pascal Dimassimo