Skip to content
Advertisement

analyzing a single elasticsearch field in different ways

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement