It looks good to me.
Could you check the response?
PutMappingResponse response = client.admin().indices()
.preparePutMapping(index)
.setType(type)
.setSource(xcontent)
.execute().actionGet();
if (!response.isAcknowledged()) {
throw new Exception("Could not define mapping for type [" +
index + "]/[" + type + "].");
}
May be there is something else wrong in your actual code. Could you gist your
full code?
--
David ;-)
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
Le 27 févr. 2014 à 00:51, Andre Encarnacao <[email protected]> a
écrit :
I am trying to use the Java API (v1.0.0) to create a custom mapping for my
index but have run into a problem. More specifically, some of my mapping fields
(for example, "format" and "index") are not being stored as part of the mapping
in Elastic Search. In fact, the only field that is being stored is the "type"
field. However, if I use the CURL API, everything works as expected and all
fields are stored properly in my mapping. Has anyone seen this problem when
using the Java API? Is this a bug? I put together a very simple example that
demonstrates my bug below:
--- SOURCE CODE ---
Client client = new TransportClient().addTransportAddress(new
InetSocketTransportAddress(_hostname,_port));
XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject().startObject("type_name")
.startObject("properties")
.startObject("ATTRIBUTE1")
.field("type","string")
.field("format","dateOptionalTime")
.endObject()
.startObject("ATTRIBUTE2")
.field("type","long")
.field("index","not_analyzed")
.endObject()
.endObject()
.endObject()
.endObject();
client.admin().indices().preparePutMapping("index_name").setType("type_name").setSource(mapping).execute().actionGet();
--- OUTPUT ---
Below is the mapping created in ES after running the code snippet above (from
http://localhost:9200/index_name/_mapping?pretty). Notice that only the "type"
fields were stored in the mapping.
{
"index_name" : {
"mappings" : {
"type_name" : {
"properties" : {
"ATTRIBUTE1" : {
"type" : "string"
},
"ATTRIBUTE2" : {
"type" : "long"
}
}
}
}
}
}
--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/d8a1ae1b-bb29-45d7-8387-e938b1c0cedc%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/C476001D-D1F7-4518-A2ED-88A1DC080F4C%40pilato.fr.
For more options, visit https://groups.google.com/groups/opt_out.