Python : How to write a simple regexp query using Elasticsearch in python?

I am trying to write a simple regexp query using elasticsearch in python that just won't work. Can anybody tell me where I'm going wrong ?

result ="my-index", body={"query": {"regexp": {"Name": "Vi.*" }}})

The indexed document is a list of names with my name also in it (Vitthal Bhandari). The above query always yields empty results when it should return my name instead. The document is properly indexed and other queries work just fine. For instance a match query gives the required result.

result ="my-index", body={"query": {"match": {"Name": "Vitthal" }}})

What is the problem with the regexp query that I'm writing that it won't give any result? Any suggestions?

The index mapping of "Name" field is something like this :

        "Name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256

RegExp is case sensitive to what's in the index (for now).
The match query automatically does the lower-casing for you while the regex (which deals with partial words) does not. Try search regexp using a lower-case search string.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.