编写查询以更新文档

时间:2018-08-07 05:13:49

标签: elasticsearch

我有以下映射和索引文档:

  "my_locations": {
    "aliases": {

    },
    "mappings": {
      "_doc": {
        "properties": {
          "location": {
            "type": "geo_point"
          },
          "name_e": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "province_e": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    },

通过以下查询,我插入了数据

PUT my_locations/_doc/1
{
  "location" : {
      "lat" : 40.92,
      "lon" : -71.34
  }
}

我忘了在上面的查询中添加name_e和province_e。如何编写更新查询以插入文档1的名称和省份?

1 个答案:

答案 0 :(得分:1)

您可以使用update API来做到这一点:

POST my_locations/_doc/1/_update
{
  "doc" : {
      "name_e": "some name",
      "province_e": "some province"
  }
}