使用 Scala 更新 ELasticSearch 中的映射定义

Update Mapping Defination is ELasticSearch using Scala

我想知道如何更新现有 INDEX 的映射。 所以我有一个索引:

{
    "state": "xxx",
    "settings": {
        "index": {
            "creation_date": "xxx",
            "number_of_shards": "xxx",
            "number_of_replicas": "xxx",
            "uuid": "xxx",
            "version": {
                "created": "xxx"
            }
        }
    },
    "mappings": {
        "es_content_entry": {
            "properties": {
                "input": {
                    "properties": {
                        "zipCode": {
                            "type": "string"
                        },
                        "address": {
                            "type": "string"
                        },
                        "cityName": {
                            "type": "string"
                        },
                    }
                }
            }
        }
    }
}

我正在使用 scala 更新此索引的映射,如下所示: CheckFieldMappingResult 是具有

的对象
indexName: String,
entryType: String,
path: Seq[String],
localMapping: Option[TypedFieldDefinition],
remoteJsonMapping : Option[JsObject],
isConsistent: Boolean,
status: String

val remoteMissingObject: Seq[CheckFieldMappingResult] = mappingConsistensyResult.filter(p => p.status == "REMOTE_MISSING")

    val entryType: Seq[String] = remoteMissingObject.map(_.entryType)
    val path: Seq[Seq[String]] = remoteMissingObject.map(_.path)
    val foo: Seq[TypedFieldDefinition] = remoteMissingObject.map(_.localMapping.get)
    print(foo)

for (remote <- remoteMissingObject)yield {
    esClient.execute{put
    putMapping(INDEX_NAME/remote.entryType).fields {
        val too: String = path.flatten.head
        println(too)
        val foo: TypedFieldDefinition = remote.localMapping.get
        foo
    }

    }
}

它给了我这个输出:

{
    "state": "xxx",
    "settings": {
        "index": {
            "creation_date": "xxx",
            "number_of_shards": "xxx",
            "number_of_replicas": "xxx",
            "uuid": "xxx",
            "version": {
                "created": "xxx"
            }
        }
    },
    "mappings": {
        "es_content_entry": {
            "properties": {
                "additionnalInfos": {
                    "type": "string"
                },
                "input": {
                    "properties": {
                        "zipCode": {
                            "type": "string"
                        },
                        "address": {
                            "type": "string"
                        },
                        "cityName": {
                            "type": "string"
                        },
                    }
                }
            }
        }
    }
}

它在索引的开头添加了附加信息,但我希望它添加这条路径INDEX_NAME\es_content_entry\input\addtionalinfos 我该怎么做?

elastic4s是基于Scala的库,支持创建索引。

https://github.com/sksamuel/elastic4s

我为所有路径值创建了一个 TypedFieldDefination 对象。

for(

  pathToken <- path.reverse.drop(1)

) {

  fullTypedFieldDefinition = FieldDefinition.objectField(Seq(fullTypedFieldDefinition))(pathToken)

}