es - elasticsearch mapping - field data type - 19

292 阅读1分钟

世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。

问:token_count有什么特点?
答:
在这里插入图片描述

问:token_count如何使用?
答:

# token count
PUT /token_count_test
{
  "mappings": {
    "properties": {
      "my_token_count": {
        "type"  : "text",
        "fields": {
          "length": {
            "analyzer": "standard",
            "type"    : "token_count"
          }
        }
      }
    }
  }
}

# 索引
POST /token_count_test/_doc
{
  "my_token_count": "hello good me"
}

# 索引
POST /token_count_test/_doc
{
  "my_token_count": "hello good"
}


# 搜索
GET /token_count_test/_search
{
  "query": {
    "term": {
      "my_token_count.length": {
        "value": "2"
      }
    }
  }
}

# 结果
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "token_count_test",
        "_type" : "_doc",
        "_id" : "QmfIYXgBVbS9eSDZfe6a",
        "_score" : 1.0,
        "_source" : {
          "my_token_count" : "hello good"
        }
      }
    ]
  }
}