scala - 更新映射定义是使用 Scala 的 ELlasticSearch
问题描述
我想知道如何更新现有 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 更新此 INDEX 的映射,如下所示: CheckFieldMappingResult is a object with
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
推荐阅读
- pandas - 读取csv文件时如何删除数据中不需要的值
- r - R:当观察数不能被箱数整除时,按一个因子创建箱?
- ios - Swift:在没有文本时以编程方式使用 numberOfLines 展开 UILabel
- vim - 如何在不提示“将更改保存到无标题?”的情况下关闭 gvim?
- windows - 具有本机反应的 Windows 应用程序
- python-3.x - 尝试使用 Python 和 psycopg2 创建 Redshift 表,但未创建表且未报告错误
- php - 我正在尝试跳过结帐页面中的付款地址
- julia - 使用 map 将 Int32 类型的新列添加到 julia 数据框
- python-3.x - Python Selenium 如何定位和填写这 3 个输入
- python - 带参数的 Python/Flask 嵌套装饰器