我需要创建一个索引,其中包含一些上下文完成建议映射,如(https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html)所示。正如我在https://github.com/sksamuel/elastic4s/issues/452中所看到的,这似乎并不受DSL的支持。
因此,从原始JSON字符串创建索引(类似于原始查询)会很不错。是否有可能实现这一目标?
答案 0 :(得分:3)
考虑到你在变量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
}