termquery与matchquery的区别

时间:2020-12-24 12:05:40   收藏:0   阅读:205
PUT test/_doc/1
{
  "content":"Hello World"
}
GET test/_mapping

{
  "test" : {
    "mappings" : {
      "properties" : {
        "content" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}
GET test/_analyze
{ 
  "explain": true, 
  "analyzer": "standard",
  "text": "Hello World"
}

POST test/_search
{
  "profile": "true",
  "query": {
    "match": {
      "content": "Hello World" 
    }
  }
}

POST test/_search
{
  "profile": "true",
  "query": {
    "match": {
      "content": "hello world"
    }
  }
}
#查的到数据,因为content.keyword在存数据的时候不分词,不做任何处理.存的就是Hello World
POST test/_search
{
  "profile": "true",
  "query": {
    "match": {
      "content.keyword": "Hello World"
    }
  }
}
#查不到数据,因为content.keyword在存数据的时候不分词,不做任何处理.存的就是Hello World,而你用小写的hello world去查询,所以查不到数据
POST test/_search
{
  "profile": "true",
  "query": {
    "match": {
      "content.keyword": "hello world"
    }
  }
}
#查不到,termquery :content:Hello World,你存的数据content是hello
POST test/_search
{
  "profile": "true",
  "query": {
    "term": {
      "content": "Hello World"
    }
  }
}
#termquery.查不到content作为整体去查
POST test/_search
{
  "profile": "true",
  "query": {
    "term": {
      "content": "hello world"
    }
  }
}
#查的到,content存的数据是Hello World,所以查得到
POST test/_search
{
  "profile": "true",
  "query": {
    "term": {
      "content.keyword": "Hello World"
    }
  }
}

 

原文:https://www.cnblogs.com/wangchuanfu/p/14182520.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!