0

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

2
  • What is the mapping type of customer_first_name? Commented Oct 2, 2020 at 7:28
  • "customer_first_name" : { "type" : "text", "fields" : { "keyword" : { "type" : "keyword", "ignore_above" : 256 } } }, Commented Oct 2, 2020 at 7:31

1 Answer 1

1

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"
        }
    }
}
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.