首页  

elasticsearch term 和 match     所属分类 elasticsearch 浏览量 1170
测试索引  
f1 字段分词 
f2 不分词

PUT /foo
{
  "mappings": {
    "properties": { 
      "f1":    { "type": "text"  }, 
      "f2":     { "type": "keyword"  }    
    }
  }
}

测试数据
{ "f1":"tiger say hello world to you","f2":"tiger say hello world to you"}
{ "f1":"Hello world","f2":"Hello world" }
{ "f1":"World Hello","f2":"World Hello" }
{ "f1":"hello","f2":"hello" }


添加测试数据

POST /foo/_doc

...





term 精确匹配


{"query":{"term":{"f1": "hello"}}}  查到4条记录
{"query":{"term":{"f1": "Hello"}}}  查不到记录
{"query":{"term":{"f1": "HELLO"}}}  查不到记录

{"query":{"term":{"f2": "hello"}}} 查到1条记录
{"query":{"term":{"f2": "Hello"}}}  查不到记录



match 模糊匹配  
对输入分词 文档只要包含match查询条件的一部分就会返回

{"query":{"match":{"f1":"hello"}}} 查到4条记录
{"query":{"match":{"f1":"Hello"}}} 查到4条记录
{"query":{"match":{"f1": "HELLO"}}} 查到4条记录

{"query":{"match":{"f1":"hello world"}}} 查到4条记录

{
   "query":{  
      "match":{  
         "f1":{  
            "query":"hello word",
            "operator":"or",
            "minimum_should_match":2
         }
      }
   }
}

查到3条记录



match 使用 f1 定义的分词器分词后再匹配



{"query":{"match":{"f2": "hello"}}} 查到1条记录
{"query":{"match":{"f2": "Hello"}}}  查不到记录
{"query":{"match":{"f2": "HELLO"}}}  查不到记录

f2 不分词 , match 直接使用精确匹配

上一篇     下一篇
elasticsearch索引_source index store doc_values 参数实例

elasticsearch term match match_phrase 区别

postman中form-data x-www-form-urlencoded raw binary的区别

kafka1.1.0无法消费问题

JMX配置及java客户端远程连接JMX端口

AQS要点整理