Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search by prefix on concatenation of fields

Did not find an answer for this on Google.

I have json objects, which contains first_name and last_name.

I want to run search that will match if the query is prefix of first_name + last_name or last_name + first_name.

E.g. for objects:

{
     "first_name":"Leo",
     "last_name": "messi"
}
{
     "first_name":"Leo",
     "last_name": "Cohen"
}
  • leo -> should match both
  • leo m-> should match the first one
  • messi l-> should match the first one
  • le -> should match both
  • co -> should match the second one
like image 746
eran Avatar asked Nov 10 '22 17:11

eran


1 Answers

I think that you can do this with a cross-field search.

See: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_cross_fields_queries.html

like image 171
Jasper Huzen Avatar answered Nov 15 '22 09:11

Jasper Huzen