Spring数据elasticsearch根据请求参数动态创建索引,percolator支持并通过Elasticsearch操作创建索引

编程入门 行业动态 更新时间:2024-10-27 02:23:03
本文介绍了Spring数据elasticsearch根据请求参数动态创建索引,percolator支持并通过Elasticsearch操作创建索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我通读了docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#reference 以

开头

我的要求

  • 我想使用过滤器.spring数据elasticsearch中是否有任何支持?我在上面的链接中没有看到任何内容,尽管我知道渗透与索引相同(技术上从使用 spring 数据弹性搜索的角度来看).所以我可以使用 spring 数据弹性搜索的索引部分,但只是检查是否有任何特定于 percolator 的内容.
  • 我想动态创建一个索引.我知道我可以使用 docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.mapping.meta-model.annotations 但是我的情况略有不同,我将通过 RequestParam 作为 API 调用的一部分获取索引名称.所以这意味着据我所知,我不能使用 SpEL 或尝试类似 stackoverflow/a/33520421/4068218
  • 我知道我可以使用 ElasticsearchOperations 或 ElasticsearchRepository 来创建索引.由于#2(即通过请求参数的索引名称),我认为 ElasticsearchOperations 更适合,但我看到 IndexOperations 促进了 createMapping、createSettings,但不能同时使用.我也看到 putMapping 但我没有看到任何说明映射和设置的内容.我想要两者的原因是我想创建像下面这样的东西
  • 设置":{索引":{number_of_shards": 1,number_of_replicas": 0}},映射":{属性":{消息":{类型":文本"},查询":{类型":渗透器"}}}

    底线:- 如何使用 ElasticsearchOperations 使用映射和设置创建索引(索引名称将通过请求参数动态变化)?非常感谢任何线索/帮助

    解决方案

    首先非常感谢@P.J.Meisch.为您的评论点赞以示感谢.

    以下为我工作.以下可能会在未来帮助其他人

    文档映射 = Document.create().fromJson("{\n" +\n"+"\"属性\":{\n"+"\"消息\":{\n"+"\"类型\":\"文本\"\n"+"},\n"+"\"查询\":{\n";+"\"类型\":\"percolator\"\n"+"}\n"+"}\n"+\n"+"}");映射settings = ImmutableMap.of(number_of_shards",2,number_of_replicas",1);elasticsearchOperations.indexOps(IndexCoordinates.of("whatever-indexname-you-need")).create(settings,mapping);

    I read through docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#reference to begin with

    My requirements

  • I want to use percolator. Is there any support for it in spring data elasticsearch? I don't see any in the above link although I understand that percolating is same as indexing (technically from using spring data elasticsearch's perspective). So I can use the indexing part of spring data elasticsearch but just checking if there are any that are specific to percolator.
  • I want to create an index dynamically. I do understand I can achieve that using SpEL template expression as mentioned in docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.mapping.meta-model.annotations but my case is slightly different, I will get the index name via the RequestParam as part of the API call. So this means as of my knowledge I cannot use SpEL or try something like stackoverflow/a/33520421/4068218
  • I see I can use ElasticsearchOperations or ElasticsearchRepository to create Index. Because of #2 (i.e index name via request parameter) I think ElasticsearchOperations better suits but I see IndexOperations facilitating createMapping, createSettings but not both together. I see putMapping too but I dont see anything that says both mapping and settings. The reason I want both is I want to create something like below to begin with
  • "settings" : { "index" : { "number_of_shards" : 1, "number_of_replicas" : 0 } }, "mappings": { "properties": { "message": { "type": "text" }, "query": { "type": "percolator" } } }

    Bottom line :- How do I create an index (name of the index will be dynamic via request param) with mappings, settings using ElasticsearchOperations? Any lead/help is much appreciated

    解决方案

    First of all thank you very much @P.J.Meisch. Upvoted both your comments as a token of gratitude.

    Below worked for me. Below might help others in future

    Document mapping = Document.create().fromJson("{\n" + "\n" + " \"properties\": {\n" + " \"message\": {\n" + " \"type\": \"text\"\n" + " },\n" + " \"query\": {\n" + " \"type\": \"percolator\"\n" + " }\n" + " }\n" + "\n" + "}"); 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);

    更多推荐

    Spring数据elasticsearch根据请求参数动态创建索引,percolator支持并通过Elasticsearch操作创建索引

    本文发布于:2023-10-13 17:10:19,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1488583.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:索引   参数   操作   动态   数据

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!