I want to know how can I analyze an elasticsearch field with two different analyzers at the same time. I am creating an elasticsearch plugin so, I need the java code to implement the same.
CodePudding user response:
you can use the multi-fields to achieve the same. Refer multiple analyzer section in the document with example.
CodePudding user response:
You can use Create Index API in java code for creating index with multi field
CreateIndexRequest request = new CreateIndexRequest("twitter");
Map<String, Object> email_second = new HashMap<>();
email_second.put("type", "text");
email_second.put("analyzer", "custom_standard");
Map<String, Object> email = new HashMap<>();
email.put("type", "text");
email.put("analyzer", "standard");
email.put("fields", "email_second");
Map<String, Object> properties = new HashMap<>();
properties.put("email", email);
Map<String, Object> mapping = new HashMap<>();
mapping.put("properties", properties);
request.mapping(mapping);
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
you can access first email field with email
and second with email.email_second
name.