0

How do i write a solr query to search for a field with only white spaces in it ? For example

{
    "phone_number":"Airtel",
    "smstype":1,
    "phone_status":-1,
    "user_hash":"52565f64ba3e8df1aa",
    "contact_name":" ",
    "snaptype":1,
}

If you notice the contact_name field, it is just two spaces, how do i filter out records which contains only spaces for a particular field ?

resay
  • 46
  • 3

4 Answers4

0

I have answered similar question here.

In the SolrQuerySytax page they says that you can use the following query to find all empty queries.

-field:[* TO *] finds all documents without a value for field
Community
  • 1
  • 1
Parvin Gasimzade
  • 25,180
  • 8
  • 56
  • 83
  • The question is not about retrieving documents without a value for a specific field, but with only whitespaces for a specific field. – javanna Jul 10 '12 at 14:00
0

I think this could be achieved by using a regex query (I am not regex expert but 'only whitespaces' is pretty easy and common).

See this for detailed info on regex support in solr/lucene

Community
  • 1
  • 1
Persimmonium
  • 15,593
  • 11
  • 47
  • 78
0

Adding to Persimmonium's answer - the following query should do the trick.

In addition to regex you will also need to escape for the space.

contact_name:"\ "*

user1452132
  • 1,758
  • 11
  • 21
0

Sorry for being a little late. A regex to find whitespace is very easy to find. You should also pay attention the tokenizer you are using. Some tokenizers will strip off the whitespace and leave the field empty.

Omar Jaafor
  • 161
  • 3
  • 12