Define custom ElasticSearch Analyzer using Java API

后端 未结 2 454
再見小時候
再見小時候 2020-12-08 05:12

Is there a way to create an index and specify a custom analyzer using the Java API? It supports adding mappings at index creation, but I can\'t find a way to do something li

相关标签:
2条回答
  • 2020-12-08 05:28

    You can set analyzer using client.admin().indices().prepareCreate("twitter").setSettings(...). There are several ways to build settings. You can load them from text, map or even use jsonBuilder if that's what you want:

    client.admin().indices().prepareCreate("twitter")
                .setSettings(Settings.settingsBuilder().loadFromSource(jsonBuilder()
                    .startObject()
                        .startObject("analysis")
                            .startObject("analyzer")
                                .startObject("steak")
                                    .field("type", "custom")
                                    .field("tokenizer", "standard")
                                    .field("filter", new String[]{"snowball", "standard", "lowercase"})
                                .endObject()
                            .endObject()
                        .endObject()
                    .endObject().string()))
                .execute().actionGet();
    
    0 讨论(0)
  • 2020-12-08 05:28

    If you are on a test environnent you can also uses this project which will create your indexes based on Java annotations. https://github.com/tlrx/elasticsearch-test

    0 讨论(0)
提交回复
热议问题