es - elasticsearch - search - DSL - term level - term

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

问:term有什么特点?
答:
es - elasticsearch - search - DSL - term level - term
问:term如何使用?
答:

# 删除
DELETE /term_test

# 映射
PUT /term_test
{
  "mappings": {
    "properties": {
      "name": {"type": "keyword"}
    }
  }
}

# 索引
POST /term_test/_doc/1?refresh
{
  "name": "hello"
}

# 索引
POST /term_test/_doc/2?refresh
{
  "name": "good"
}

# 索引
POST /regexp_test/_doc/3?refresh
{
  "name": "me"
}

# 索引
POST /term_test/_doc/4?refresh
{
 "name": "hello"
}


# 搜索 - 针对term
GET /term_test/_search
{
  "query": {
    "term": {
      "name": {
        "value": "hello"
      }
    }
  }
}

# 结果
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.4700036,
    "hits" : [
      {
        "_index" : "term_test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.4700036,
        "_source" : {
          "name" : "hello"
        }
      },
      {
        "_index" : "term_test",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 0.4700036,
        "_source" : {
          "name" : "hello"
        }
      }
    ]
  }
}

上一篇:JavaDoc


下一篇:解决浏览器兼容问题