【问题标题】:Create index from raw JSON using elastic4s使用 elastic4s 从原始 JSON 创建索引
【发布时间】:2016-06-25 02:50:58
【问题描述】:

我需要创建一个索引,其中包含一些上下文完成建议器映射,如 (https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html)。正如我在https://github.com/sksamuel/elastic4s/issues/452 中看到的,这似乎不受DSL 的支持。

因此,最好从原始 JSON 字符串创建索引(类似于原始查询)。有没有可能做到这一点?

【问题讨论】:

    标签: scala elasticsearch elastic4s


    【解决方案1】:

    考虑到您在变量 rawMapping 中有 JSON 映射,如下所示:

    val rawMapping =
        """{
              "service": {
                      "properties": {
                          "name": {
                              "type" : "string"
                          },
                          "tag": {
                              "type" : "string"
                          },
                          "suggest_field": {
                              "type": "completion",
                              "context": {
                                  "color": {
                                      "type": "category",
                                      "path": "color_field",
                                      "default": ["red", "green", "blue"]
                                  },
                                  "location": {
                                      "type": "geo",
                                      "precision": "5m",
                                      "neighbors": true,
                                      "default": "u33"
                                  }
                          }
                      }
                  }
                  }
              }"""
    

    您可以像这样使用原始映射创建索引:

    client.execute {
        create index "services" source rawMapping
    }
    

    【讨论】:

    • 您需要rawmapping 字符串以"mappings" : { ... } 开头。 API 现在是createIndex("services") source rawMapping
    猜你喜欢
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    相关资源
    最近更新 更多