【问题标题】:Elasticsearch: how can i convert long data-type into keyword or textElasticsearch:如何将长数据类型转换为关键字或文本
【发布时间】:2022-08-18 15:52:38
【问题描述】:

我想将具有长数据类型的字段 \'districId\' 转换为关键字/文本以进行通配符搜索。请指导我如何在弹性搜索中将数据类型从 long 转换为关键字/文本数据类型

PUT geoxingsite/_mapping
{
    \"properties\": {
      \"districtId\": {
        \"type\": \"keyword\"
      }
    }
}

我在下面收到错误...

{
  \"error\" : {
    \"root_cause\" : [
      {
        \"type\" : \"illegal_argument_exception\",
        \"reason\" : \"mapper [districtId] cannot be changed from type [long] to [keyword]\"
      }
    ],
    \"type\" : \"illegal_argument_exception\",
    \"reason\" : \"mapper [districtId] cannot be changed from type [long] to [keyword]\"
  },
  \"status\" : 400
}
  • 你能显示一个你想在districtId 上运行的通配符查询吗?

标签: javascript elasticsearch logstash


【解决方案1】:

字段一旦创建就无法更改其类型。但是,您可以像这样添加子字段:

PUT geoxingsite/_mapping
{
    "properties": {
      "districtId": {
        "type": "long",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      }
    }
}

完成后,您需要使用更新您的索引

POST geoxingsite/_update_by_query?wait_for_completion=false

任务运行后,您将拥有一个名为 districtId.keyword 的新字段,您可以在该字段上运行通配符查询

【讨论】:

    猜你喜欢
    • 2022-11-24
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 2016-09-19
    • 1970-01-01
    • 2013-05-12
    相关资源
    最近更新 更多