Unknown setting [index.analysis]

I'm creating my index with org.elasticsearch Java API (6.3.0) in the following function:

private void createIndex(String type) throws IOException {
boolean existent =
config.getClient()
.admin()
.indices()
.prepareExists(CommonUtil.indexName(type))
.execute()
.actionGet()
.isExists();

  if (!existent) {
  	HashMap<String, Object> settings = new HashMap<>();

  	settings.put("number_of_shards", 1);
  	settings.put("number_of_replicas", 1);

  	String analysis = "{ 'analyzer': { 'case_insensitive_sort': { 'type': 'custom', 'char_filter': [], 'filter':  [ 'lowercase' ] } } }";

  	CreateIndexRequestBuilder cirb = 
  			config.getClient()
  				.admin()
  				.indices()
  				.prepareCreate(CommonUtil.indexName(type))
  				.setSettings(settings);

  	CreateIndexResponse createIndexResponse = cirb.execute().actionGet();

  	if (createIndexResponse != null && createIndexResponse.isAcknowledged()) {
  		config.getClient()
  			.admin()
  			.indices()
  			.prepareUpdateSettings(CommonUtil.indexName(type))
  			.setSettings(Settings.builder().put("analysis", analysis)).get();
  	} else {
  		// Index creation failed
  	}
  }

}

This return me javax.ejb.EJBException: java.lang.IllegalArgumentException: unknown setting [index.analysis] please check that any required plugins are installed, or check the breaking changes documentation for removed settings. How can I init an analysis to implement case insensitive sort?

You can't pass that:

"{ 'analyzer': { 'case_insensitive_sort': { 'type': 'custom', 'char_filter': [], 'filter':  [ 'lowercase' ] } } }"

Within .put("analysis", analysis) method.

The REST Client has the following implementation: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-create-index.html#_providing_the_whole_source

Which can help you.

You should move away from the TransportClient as it will be removed in the future. But I believe the TransportClient has a similar method as the REST client. I did not check though.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.