elasticsearch - 如何在不破坏Elasticsearch中数据的情况下更改架构?

标签 elasticsearch

这是我目前的模式

{
    "mappings": {
      "historical_data": {
        "properties": {
          "continent": {
            "type": "string",
            "index": "not_analyzed"
          },
          "country": {
            "type": "string",
            "index": "not_analyzed"
          },
          "description": {
            "type": "string"
          },
          "funding": {
            "type": "long"
          },
          "year": {
            "type": "integer"
          },
          "agency": {
            "type": "string"
          },
            "misc": {
            "type": "string"
          },
          "university": {
            "type": "string",
            "index": "not_analyzed"
          }
        }
      }
    }
}

我上传了70万条记录。在不破坏数据的情况下,如何使大学索引不被“not_analysed”,以使更改反射(reflect)在现有数据中?

最佳答案

现有字段的映射无法修改。
但是,您可以通过两种方式实现所需的结果。

  • 创建另一个字段。使用put _mapping API
  • 免费添加字段

    curl -XPUT localhost:9200/YOUR_INDEX/_mapping -d '{
      "properties": {
        "new_university": {
          "type": "string"
        }
      }
    }'
    

  • 使用multi-fields,将一个子字段添加到not_analyzed字段中。

  • curl -XPUT localhost:9200/YOUR_INDEX/_mapping -d '{
        "properties": {
            "university": {
                "type": "string",
                "index": "not_analyzed",
                "fields": {
                    "university_analyzed": {
                        "type": "string" // <-- ANALYZED sub field
                    }
                }
            }
        }
    }'
    


    在这两种情况下,都需要重新索引以便填充新字段。使用_reindex API
    curl -XPUT localhost:9200/_reindex -d '{
      "source": {
        "index": "YOUR_INDEX"
      },
      "dest": {
        "index": "YOUR_INDEX"
      },
      "script": {
        "inline": "ctx._source.university = ctx._source.university"
      }
    }'
    

    关于elasticsearch - 如何在不破坏Elasticsearch中数据的情况下更改架构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42711865/

    相关文章:

    python - ElasticSearch 字段提升

    java - elasticsearch date_format异常

    python - Scrapy - 数据库选择

    java - 为什么在 Elastic 搜索中引入 Java 高级 REST 客户端?

    json - 在负载中指定 elasticsearch 索引

    windows - Windows 中的 ElasticSearch docker image vm max map count

    json - Filebeat 和 LogStash——多种不同格式的数据

    elasticsearch - 如何在休眠 Elasticsearch 中组合多个QueryDescriptor

    elasticsearch - 从Kafka流到Elasticsearch时的主题映射

    elasticsearch - Logstash不适用于输入文本文件