1

I am running elasticsearch v1.1.1 and I am having trouble getting results from regex searches.

{
 "query" : {
   "regexp" : {
           "lastname" : "smit*"
    }
  }
}

Returns 0 results (when I know I have 'smith' in the data.

I have also tried:

{
  "query" : {
   "filtered" : {
        "filter" : {
             "regexp" : {
                   "lastname" : "smit*"
             }
         }
    }
  }
}

Any help would be appreciated.

1
  • Please, post a sample of your data. Commented Dec 10, 2014 at 21:25

1 Answer 1

2

So first off, a lot of this is dependent on how you indexed the field - analyzed or not, what kind of tokenizer, was it lowercased, etc.

To answer your specific question concerning regexp queries, assuming your field is indexed as "smith" (all lower case) you should change your search string to "smit.*" which should match "smith". "smit." should also work.

The reason is that in regexp (which is different than wildcard) "." matches any character. "*" matches any number of the previous character. So your search would match "smitt" or "smittt". The construct ".*" means match any number (including 0) of the previous character - which is "." which matches any. The combination of the two is the regexp equivalent of the wildcard "*".

That said, I'd caution that regexp and wildcard searches can have significant performance challenges in text indexes, depending upon the nature of the field, how it's indexed and the number of documents. These kinds of searches can be very useful but more than one person has built wildcard or regexp searches tested on small data sets only to be disappointed by the production performance. Use with caution.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html

ElasticSearch Regexp Filter

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.