I am using elasticsearch-6.1.1.As the CreateIndexRequest api is not provided by JavaHighLeve client-6.1.1 i tried to create the index by working around with TransportClient as given here:(https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/_changing_the_application_8217_s_code.html) The code is:
public class IndexOperations {
RestHighLevelClient client ;
public IndexOperations(RestHighLevelClient client){
this.client = client ;
}
public void indexOperations()throws UnknownHostException,IOException {
TransportClient transportClient = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"),9300));
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("delllogfiles")
.startObject("properties")
.startObject("message")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("logid")
.field("type","long")
.endObject()
.startObject("version")
.field("type","long")
.endObject()
.startObject("qualifiers")
.field("type","text")
.endObject()
.startObject("level")
.field("type","long")
.endObject()
.startObject("task")
.field("type","long")
.endObject()
.startObject("opcode")
.field("type","long")
.endObject()
.startObject("keywords")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("recordid")
.field("type","long")
.endObject()
.startObject("providername")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("providerid")
.field("type","long")
.endObject()
.startObject("logname")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("processid")
.field("type","long")
.endObject()
.startObject("threadid")
.field("type","long")
.endObject()
.startObject("machinename")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("userid")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("timecreated")
.field("type","date")
.endObject()
.startObject("activityid")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("relatedactivityid")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("containerlog")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("matchedqueryids")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("bookmark")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("levldispalyname")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("opcodedisplayname")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("taskdisplayname")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("keywordsdisplayname")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.startObject("properties")
.field("type","text")
.field("index","not_analyzed")
.endObject()
.endObject()
.endObject()
.endObject()
.string();
CreateIndexResponse createIndexResponse = transportClient.admin().indices()
.prepareCreate("logfiles")
.addMapping("delllogfiles",mapping,XContentType.JSON)
.get();
System.out.println("finally index created "+createIndexResponse.isAcknowledged());
transportClient.close();
when is run the code i get an exception as :
Exception in thread "main" MapperParsingException[Failed to parse mapping [delllogfiless]: Could not convert [message.index] to boolean]; nested: IllegalArgumentException[Could not convert [message.index] to boolean]; nested: IllegalArgumentException[Failed to parse value [not_analyzed] as only [true] or [false] are allowed.];
How can i set anaylzer of a field to not_analyzed when using TransportClient ?
From elastic search 5 index property has only two options
For not_analyzed string fields use field type keyword instead of text which is by default not_analyzed
Here is the link to it. https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With