ElasticSearch match, match_phrase, term区别

转自 https://www.cnblogs.com/buxizhizhoum/p/9874703.html

1.term结构化字段查询,匹配一个值,且输入的值不会被分词器分词。

  比如查询条件是:

{
    "query":{
        "term":{
            "foo": "hello world"
        }
    }
}

那么只有在字段中存储了“hello world”的数据才会被返回,如果在存储时,使用了分词,原有的文本“I say hello world”会被分词进行存储,不会存在“hello world”这整个词,那么不会返回任何值。

但是如果使用“hello”作为查询条件,则只要数据中包含“hello”的数据都会被返回,分词对这个查询影响较大。

2.match_phase习语匹配,查询确切的phase,在对查询字段定义了分词器的情况下,会使用分词器对输入进行分词,然后返回满足下述两个条件的document:

  1.match_phase中的所有term都出现在待查询字段之中

  2.待查询字段之中的所有term都必须和match_phase具有相同的顺序

{ "foo":"I just said hello world" }

{ "foo":"Hello world" }

{ "foo":"World Hello" }

使用match_phase:

{
  "query": {
    "match_phrase": {
      "foo": "Hello World"
    }
  }
}

会返回前两条文档。

3.match模糊匹配,先对输入进行分词,对分词后的结果进行查询,文档只要包含match查询条件的一部分就会被返回。

猜你喜欢

转载自blog.csdn.net/zch3210/article/details/89099685