elasticsearch - 有没有办法知道 Elasticsearch 中键的数据类型?

标签 elasticsearch querydsl elasticsearch-painless

我面临着诸如 key 数据类型改变之类的问题。在创建索引时,我有嵌套的数据类型,但由于某种原因,它被更改为对象。我通过无痛脚本进行 CRUD 操作,但这似乎很好。
弹性版本 7.3.0
初始模板:

"settings": {
  "number_of_shards": 1,
},
"mappings" : {
  "properties": {
    "deleted_at": { "type": "date" },
    "updated_at": { "type": "date" },
    "id": { "type": "integer" },
    "user_id": { "type": "integer" },

    ... some more keys

    "user_tags": {
      "type": "nested"
    },
    "user_files": {
      "type": "nested"
    },
  }
}
一些批量插入/更新后的映射
"mappings" : {
  "properties": {
    "deleted_at": { "type": "date" },
    "updated_at": { "type": "date" },
    "id": { "type": "integer" },
    "user_id": { "type": "integer" },
    "user_tags": {
      "properties": {
        ...some properties
      }
    },
    "user_files": {
      "properties": {
        ...some properties
      }
    },
  }
}
我必须重新索引来解决这个问题,但它经常发生。还有什么方法可以知道键的数据类型是嵌套的还是对象的?
提前致谢。

最佳答案

通过设置 "dynamic": "strict"您的映射不会更改,并且不会插入不合适的文档。要解决此问题,您需要定义要位于嵌套字段内的所有字段。例如:

{
"user_tags": {
            "type": "nested",
            "properties": {
              "code": {
                "type": "keyword",
                "store": true
              },
              "score": {
                "type": "float",
                "store": true
              }
              
            }
          }
}
如果您只想存储一个列表,您可以使用如下映射:
{
    "user_tags": {
            "type": "keyword",
            "store": true
          }
}
在第二个映射中,您可以使用此结果存储 user_tags ["tag1", "tag2", ...]

关于elasticsearch - 有没有办法知道 Elasticsearch 中键的数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64370940/

相关文章:

elasticsearch - 如何基于保存的搜索中的日期字段显示到期,过期和未到期

elasticsearch - 如何在嵌套 script_score 的过滤器之间添加?

elasticsearch - 在Elasticsearch中按排序查询删除

elasticsearch - 如何仅在Elasticsearch中的嵌套对象数组中搜索最近插入的对象(通过日期字段知道)

java - Querydsl - 在 pom.xml 中注册自定义类型

postgresql - 如何在querydsl中减去小时数?

arrays - 在Elasticsearch中轻松检索数组的最后一个元素的信息

elasticsearch - 如何将一些 ElasticSearch 数据复制到新索引

elasticsearch - 如何使用reindex API重命名索引

elasticsearch - Querydsl与ES Querydsl