您现在的位置是:首页 > 博客日记 > Search搜索 Search搜索

ElasticSearch match, match_phrase, term区别

2020-11-05 16:32:55 【Search搜索】 人已围观

ElasticSearch match, match_phrase, term区别

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

比如查询条件是:

  1. {
  2. "query":{
  3. "term":{
  4. "foo": "hello world"
  5. }
  6. }
  7. }

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

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

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

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

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

  1. { "foo":"I just said hello world" }
  2. { "foo":"Hello world" }
  3. { "foo":"World Hello" }

使用match_phase:

  1. {
  2. "query": {
  3. "match_phrase": {
  4. "foo": "Hello World"
  5. }
  6. }
  7. }

会返回前两条文档。

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

4.query_string语法查询,同match_phase的相同点在于,输入的查询条件会被分词,但是不同之处在与文档中的数据可以不用和query_string中的查询条件有相同的顺序。



关注TinyMeng博客,更多精彩分享,敬请期待!
 

很赞哦! ()