es - elasticsearch search - fields

·  阅读 68

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

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

问:fields如何使用?

# fields
PUT /fields_test
{
  "mappings": {
    "dynamic"   : "strict",
    "properties": {
      "name": {"type": "text"}
    }
  }
}

# 索引
POST /fields_test/_doc/1
{
  "name": "hello good"
}

# 搜索
GET /fields_test/_search
{
  "query": {
    "match": {
      "name": "hello"
    }
  },
  "fields" : ["name"],
  "_source": false
}

# 结果
{
  "took" : 712,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.2876821,
    "hits" : [
      {
        "_index" : "fields_test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.2876821,
        "fields" : {
          "name" : [
            "hello good"
          ]
        }
      }
    ]
  }
}
复制代码
分类:
后端
标签:
收藏成功!
已添加到「」, 点击更改