{ "query": { "bool": { "should": [ { "multi_match": { "query": "joe", "fields": [ "personName^-1.0", "person.city^-1.0", "person.street^-1.0" ], "type": "phrase_prefix", "lenient": "true" } } ], "boost": 1.0, "minimum_should_match": "1" } }, "from": 0, "size": 20 }
我的问题是,我的数据库中有很多人,我想添加一些性能增强功能,这样我将接收“country”这个人,然后只搜索那个国家的人。
所以我尝试了以下方法:
{ "query": { "bool": { "must": [ { "term": { "country": { "boost": "0.0", "value": "US" } } } ], "should": [ { "multi_match": { "query": "joe", "fields": [ "personName^-1.0", "person.city^-1.0", "person.street^-1.0" ], "type": "phrase_prefix", "lenient": "true" } } ], "boost": 1.0, "minimum_should_match": "1" } }, "from": 0, "size": 20 }
但它不起作用……我没有得到任何结果,我想。。
我的对象如下所示:
{ "personName": "joey", "country": "US", "city": "LA", "street": "hollywood", }
我的映射:
{ "people": { "mappings": { "vendors": { "properties": { "country": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "personName": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "street": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "city": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } } }
这可能会解决你的问题, 只需使用country.keyword更改country字段,它将使用未分析的字段。
{ "query": { "bool": { "must": [ { "term": { "country.keyword": { "boost": "0.0", "value": "US" } } } ], "should": [ { "multi_match": { "query": "joe", "fields": [ "personName^-1.0", "person.city^-1.0", "person.street^-1.0" ], "type": "phrase_prefix", "lenient": "true" } } ], "boost": 1.0, "minimum_should_match": "1" } }, "from": 0, "size": 20 }