我正在尝试搜索full_name,电子邮件或电话
例如
如果我开始输入“+16”,它应该显示所有电话号码开始或包含“+16”的用户。全名和电子邮件相同
我的ES配置是:
{
"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" : {}
}
}
按名称
的名称搜索名称'Robert'curl -XGET'localhost:9200 / users / _search?pretty'-d' { “查询”:{ “比赛”: { “_all”:“抢劫” } } }“
不会使用全名给出预期结果。
答案 0 :(得分:1)
由于您的分析器设置在full_name
,phone
和email
字段上,因此您不应使用_all
字段,而应枚举multi_match
中的字段} query,像这样:
curl -XGET 'localhost:9200/users/_search?pretty' -d'{
"query": {
"multi_match": {
"query": "this is a test",
"fields": [
"full_name",
"phone",
"email"
]
}
}
}'