您可能想了解一下analysis 的工作原理。
还可以看看phrase matching 的这个描述。短语中的术语不必按照查询的确切顺序出现,第一个只需要出现在第二个之前。由于在"world" 之后有一个"hello",因此该文档与您的查询匹配。
还要注意,这里使用了standard analyzer,用于索引文档和分析查询,因为没有指定其他分析器。如果您愿意,您可以自定义此行为。
作为一个简单的例子,我创建了一个简单的索引:
PUT /test_index
然后索引您的文档(换行符转义):
PUT /test_index/doc/1
{
"doc_text": "Hello World and \n\nbmw Master World\n\nHello"
}
然后索引另一个删除了最后一个“Hello”:
PUT /test_index/doc/2
{
"doc_text": "Hello World and \n\nbmw Master World"
}
现在,如果我运行您的查询,则只返回第一个文档:
POST /test_index/_search
{
"query": {
"match_phrase": {
"doc_text": "World Hello"
}
}
}
...
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.4459011,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_score": 0.4459011,
"_source": {
"doc_text": "Hello World and \n\nbmw Master World\n\nHello"
}
}
]
}
}
您可以使用term vectors 向自己证明为什么会发生这种情况。我不会在这里详细介绍,但如果您愿意,可以使用以下代码进行调查:
http://sense.qbox.io/gist/3ee955b8389d1b36ea56788654955c519e2bb429