Bug in Java PutMapping API?

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 elasticsearch+unsubscribe@googlegroups.com.
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.

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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 27 févr. 2014 à 00:51, Andre Encarnacao andre.v.encarnacao@gmail.com 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 elasticsearch+unsubscribe@googlegroups.com.
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 elasticsearch+unsubscribe@googlegroups.com.
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.

@Andre might be a stupid question, but why are you trying to set a format
for a string field and set 'index' on a long field? Afaics from the guide
(Elasticsearch Platform — Find real-time answers at scale | Elastic)
neither of these things are supported, so is it that surprising that
elasticsearch drops the invalid attributes?

On Wednesday, February 26, 2014 11:51:32 PM UTC, Andre Encarnacao wrote:

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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/fae41878-ce9d-41ea-9f84-24acd0657095%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

David and Tim:

Thanks for the quick feedback. It turns out that Tim was correct in that ES
was dropping the invalid attributes from my custom mapping. Thanks for
pointing that out and for providing a reference to the mapping core types
guide (very useful). I'm quickly getting my feet wet with ES and will
likely run into more issues like this in the future. I appreciate the help.

Thanks,
Andre

On Thu, Feb 27, 2014 at 1:24 AM, Tim S timstibbs@gmail.com wrote:

@Andre might be a stupid question, but why are you trying to set a format
for a string field and set 'index' on a long field? Afaics from the guide (
Elasticsearch Platform — Find real-time answers at scale | Elastic)
neither of these things are supported, so is it that surprising that
elasticsearch drops the invalid attributes?

On Wednesday, February 26, 2014 11:51:32 PM UTC, Andre Encarnacao wrote:

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 a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/KYNGZljgCO8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/fae41878-ce9d-41ea-9f84-24acd0657095%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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAM4eDdX%3DkyOfAvxp0-YvOtwc2nh0cixtatupV57X_1XQGov1RA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.