0
votes

I'm trying to search full_name, email or phone

For example

if i start input "+16", it should display all users with phone numbers start or contains "+16". The same with full name and email

My ES config is:

{
   "users" : {
      "mappings" : {
         "user" : {
            "properties" : {
               "full_name" : {
                  "analyzer" : "trigrams",
                  "include_in_all" : true,
                  "type" : "string"
               },
               "phone" : {
                  "type" : "string",
                  "analyzer" : "trigrams",
                  "include_in_all" : true
               },
               "email" : {
                  "analyzer" : "trigrams",
                  "include_in_all" : true,
                  "type" : "string"
               }
            },
            "dynamic" : "false"
         }
      },
      "settings" : {
         "index" : {
            "creation_date" : "1472720529392",
            "number_of_shards" : "5",
            "version" : {
               "created" : "2030599"
            },
            "uuid" : "p9nOhiJ3TLafe6WzwXC5Tg",
            "analysis" : {
               "analyzer" : {
                  "trigrams" : {
                     "filter" : [
                        "lowercase"
                     ],
                     "type" : "custom",
                     "tokenizer" : "my_ngram_tokenizer"
                  }
               },
               "tokenizer" : {
                  "my_ngram_tokenizer" : {
                     "type" : "nGram",
                     "max_gram" : "12",
                     "min_gram" : "2"
                  }
               }
            },
            "number_of_replicas" : "1"
         }
      },
      "aliases" : {},
      "warmers" : {}
   }
}

Searching for name 'Robert' by part of name

curl -XGET 'localhost:9200/users/_search?pretty' -d' { "query": { "match": { "_all": "rob" } } }'

doesn't give expected result, only using full name.

1
This answer should help: stackoverflow.com/questions/36199531/…Val
@Val it doesn't work for _all fieldsNeverBe

1 Answers

1
votes

Since your analyzer is set on the fields full_name, phone and email, you should not use the _all field but enumerate those fields in your multi_match query, like this:

curl -XGET 'localhost:9200/users/_search?pretty' -d'{
  "query": {
    "multi_match": {
      "query": "this is a test",
      "fields": [
        "full_name",
        "phone",
        "email"
      ]
    }
  }
}'