Vote count:
0
I'm in trouble with the overwriting action of prepareIndex method in Elasticsearch Java API.
The problem is that my mapping definition has changed after new document has indexed.
First of all, I defined an mapping to set "not_analyzed" index for a particular field.
String json = myMethodToGetMapping();
PutMappingResponse pmrs = client.admin().indices().preparePutMapping("my_index").setType("my_type").setSource(json).setIgnoreConflicts(true).execute().actionGet();
if (pmrs == null || !pmrs.isAcknowledged()) {
System.out.println("Put Mapping Failure.");
} else {
System.out.println("Put Mapping Success.");
}
In my mapping string(json), there is a field has settings like below.
"myFieldExact":{
"type":"string",
"index": "not_analyzed",
"dynamic": false
}
After the code has executed, I could see the proper mapping which I want to get.
curl -XGET http://{my_ip_address}:9200/my_index/my_type/_mapping/
{"my_type":{"properties":{........ "myFieldExact":{"type":"string","index":"not_analyzed","omit_norms":true,"index_options":"docs"},...... }}}
HOWEVER, this mapping has been changed after I put some data using Java API prepareIndex.
MyObject myObject = new MyObject();
myObject.setMyFieldExact("some-value");
String json = new org.codehaus.jackson.map.ObjectMapper().writeValueAsString(myObject);
client.prepareIndex("my_index", "my_type", "my_id")
.setSource(json).execute().actionGet();
The document successfully indexed into "my_index/my_type/my_id".
Here is the problem I have.
After the new record has been indexed, the original mapping definition has changed like below.
curl -XGET http://{my_ip_address}:9200/my_index/my_type/_mapping/
{"my_type":{"properties":{........ "myFieldExact":{"type":"string"},...... }}}
In short, the "index":"not_analyzed" property has been gone after the new document has indexed.
Is there anyone can help me?
Thank you very much in advance.
Aucun commentaire:
Enregistrer un commentaire