Steve
Steve

Reputation: 4563

ElasticSearch regex return no result

I have this query using match type and it returns results.

POST /kibana_sample_data_ecommerce/_search
{
    "query": {
        "match": {
            "customer_first_name": "Mary"
        }
    }
}

But when I use regex type, it return no result.

POST /kibana_sample_data_ecommerce/_search
{
    "query": {
        "regexp": {
            "customer_first_name": "M[a-z]ry"
        }
    }
}

enter image description here

Upvotes: 0

Views: 317

Answers (1)

Val
Val

Reputation: 217554

Since customer_first_name is analyzed, you need to do it like this (see the lowercase m):

POST /kibana_sample_data_ecommerce/_search
{
    "query": {
        "regexp": {
            "customer_first_name": "m[a-z]ry"
        }
    }
}

Or you can also use the keyword sub-field in order to achieve what you want:

POST /kibana_sample_data_ecommerce/_search
{
    "query": {
        "regexp": {
            "customer_first_name.keyword": "M[a-z]ry"
        }
    }
}

Upvotes: 1

Related Questions