【发布时间】:2018-04-21 06:47:30
【问题描述】:
我遇到了一个问题,当我在 Elasticsearch 中使用 match_phrase_prefix 查询时,它没有返回我期望的所有结果,尤其是当查询是一个单词后跟一个字母时。
采用这个索引映射(这是一个人为的保护敏感数据的例子):
http://localhost:9200/test/drinks/_mapping
返回:
{
"test": {
"mappings": {
"drinks": {
"properties": {
"name": {
"type": "text"
}
}
}
}
}
}
在数以百万计的其他记录中,有这些:
{
"_index": "test",
"_type": "drinks",
"_id": "2",
"_score": 1,
"_source": {
"name": "Johnnie Walker Black Label"
}
},
{
"_index": "test",
"_type": "drinks",
"_id": "1",
"_score": 1,
"_source": {
"name": "Johnnie Walker Blue Label"
}
}
如下查询,即一个单词后两个字母:
POST http://localhost:9200/test/drinks/_search
{
"query": {
"match_phrase_prefix" : {
"name" : "Walker Bl"
}
}
}
返回这个:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.5753642,
"hits": [
{
"_index": "test",
"_type": "drinks",
"_id": "2",
"_score": 0.5753642,
"_source": {
"name": "Johnnie Walker Black Label"
}
},
{
"_index": "test",
"_type": "drinks",
"_id": "1",
"_score": 0.5753642,
"_source": {
"name": "Johnnie Walker Blue Label"
}
}
]
}
}
而这个查询只有一个单词和一个字母:
POST http://localhost:9200/test/drinks/_search
{
"query": {
"match_phrase_prefix" : {
"name" : "Walker B"
}
}
}
不返回任何结果。这里会发生什么?
【问题讨论】:
标签: elasticsearch match missing-data querying