0

I have data that contains email id's of people, in the format of firstname.lastname@example.com, for example-

abc.def@example.com
stu.vwx@example
abd.rew@example.com
acw.try@example.com
swe.ewq@example.com

I want a query that gives me the first name results which I type in the search bar. For example,

Input -

a

Result -

abc
abd
acw

Input-

ab

Result-

abc
abd

Could someone please help me in how can I achieve this using the Elasticsearch query?

Frosted Cupcake
  • 1,909
  • 2
  • 20
  • 42
  • Does this answer your question? [Elasticsearch "starts with" first word in phrases](https://stackoverflow.com/questions/29741641/elasticsearch-starts-with-first-word-in-phrases) – Ravi Teja Muddada Mar 19 '21 at 13:19

1 Answers1

0

Regard to you index mapping if your email field is text type you can get desired result by this query

GET /yourindexname/_search
{
  "query": {
        "match_phrase_prefix" : {
        "email": {
            "query" : "a"
        }
      }
    }
}

As you may know we can get our index mapping by below api

GET /yourindexname/_mapping
Lunatic
  • 1,519
  • 8
  • 24