添加嵌套在现有elasticsearch索引中的类型的新字段

xxhby3vn  于 2021-07-15  发布在  ElasticSearch
关注(0)|答案(0)|浏览(171)

我有如下Map的elasticsearch索引:

{
  "myindex": {
    "mappings": {
      "properties": {
        "history": {
          "properties": {
            "name": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "timestamp": {
              "type": "date"
            }
          }
        }
      }
    }
  }
}

现在,我想对history字段编写查询,该字段是一个数组,name=“”but timestamp<'2021-01-01',但这可能会给出错误的结果,因为字段类型没有按此处所述嵌套:https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html
所以,我想让这个字段成为嵌套的,但我不认为我们可以通过简单地更新Map使现有字段成为嵌套的。如果可能的话请告诉我。
因此,我所做的是在Map中创建一个新字段并将其定义为嵌套:
放https://endpoint/myindex/_mapping/_doc?include_type_name=true

{
    "properties": {
      "historyNested": {
        "type": "nested" 
      }
    }
}

我正在使用elasticsearch 7。已成功更新。我想确认我做得是否正确。
我尝试插入更多的文档并尝试运行嵌套查询,看起来它们工作正常。但是我想在这个社区确认我是否使用了正确的方法来更新Map。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题