我通读了https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#reference开始
我的要求
"settings" : { "index" : { "number_of_shards" : 1, "number_of_replicas" : 0 } }, "mappings": { "properties": { "message": { "type": "text" }, "query": { "type": "percolator" } } }
底线:- 如何使用 ElasticsearchOperations 创建具有映射和设置的索引(索引名称将通过请求参数动态化)?
非常感谢任何领导/帮助
首先非常感谢@P.J.Meisch。对您的两条评论都点赞以表谢意。
以下对我有用。以下可能会对其他人有所帮助
Document mapping = Document.create().fromJson("""
{
"properties": {
"message": {
"type": "text"
},
"query": {
"type": "percolator"
}
}
}""");
Map<String, Object> settings = ImmutableMap.of( "number_of_shards" ,2,"number_of_replicas",1);
elasticsearchOperations.indexOps(IndexCoordinates.of("whatever-indexname-you-need")).create(settings,mapping);