Dynamic Templates using Java API

Hi,

I'm facing a problem with the dynamic templates when I try to set them
using the Java API.

When I'm using the following curl command everything is fine.

curl -X POST "http://localhost:9200/myindex" -d '{
"mappings" : {
"mytype": {
"dynamic_templates":[{
"list_mapping": {
"match":"list__",
"mapping":{
"index" : "not_analyzed"
}
}
},{
"set_mapping": {
"match":"set__
",
"mapping":{
"index" : "not_analyzed"
}
}
}
]
}
}
}'

I tried to do the same in various ways using Java, but non of them was
successful.
Here is a gist https://gist.github.com/1328836 with my initial guess in
Java.

If you run it, the output will be "{"mytype":{"properties":{}}}" , but this
is obviously wrong, and If I try to index some documents with field names
matching list__* or set__* they will be analyzed.
On the other side with the curl command everything works great.

Didn't try out the code, but the bracket in line 37 seems wrong IMHO;

Best Regards

On 31 Okt., 22:05, Bojidar Penchev dcode...@gmail.com wrote:

Hi,

I'm facing a problem with the dynamic templates when I try to set them
using the Java API.

When I'm using the following curl command everything is fine.

curl -X POST "http://localhost:9200/myindex" -d '{
"mappings" : {
"mytype": {
"dynamic_templates":[{
"list_mapping": {
"match":"list__",
"mapping":{
"index" : "not_analyzed"
}
}
},{
"set_mapping": {
"match":"set__
",
"mapping":{
"index" : "not_analyzed"
}
}
}
]
}
}

}'

I tried to do the same in various ways using Java, but non of them was
successful.
Here is a gist https://gist.github.com/1328836with my initial guess in
Java.

If you run it, the output will be "{"mytype":{"properties":{}}}" , but this
is obviously wrong, and If I try to index some documents with field names
matching list__* or set__* they will be analyzed.
On the other side with the curl command everything works great.

Unfortunately the problem is not with the bracket in line 37.
I tried without the brackets but , then I got exception related to the
parsing of the JSON.
And also the same JSON string works fine with curl.

I think the problem is with the Java command, maybe I don't send the JSON
mapping in right way, or maybe it's a bug.

On Mon, Oct 31, 2011 at 11:50 PM, K.B. korbinian.bachl@googlemail.comwrote:

Didn't try out the code, but the bracket in line 37 seems wrong IMHO;

Best Regards

On 31 Okt., 22:05, Bojidar Penchev dcode...@gmail.com wrote:

Hi,

I'm facing a problem with the dynamic templates when I try to set them
using the Java API.

When I'm using the following curl command everything is fine.

curl -X POST "http://localhost:9200/myindex" -d '{
"mappings" : {
"mytype": {
"dynamic_templates":[{
"list_mapping": {
"match":"list__",
"mapping":{
"index" : "not_analyzed"
}
}
},{
"set_mapping": {
"match":"set__
",
"mapping":{
"index" : "not_analyzed"
}
}
}
]
}
}

}'

I tried to do the same in various ways using Java, but non of them was
successful.
Here is a gist https://gist.github.com/1328836with my initial guess in
Java.

If you run it, the output will be "{"mytype":{"properties":{}}}" , but
this
is obviously wrong, and If I try to index some documents with field names
matching list__* or set__* they will be analyzed.
On the other side with the curl command everything works great.

OK, the problem is solved :slight_smile:

I removed the the root mapping element from JSON and now the dynamic
templates are working.

This is the JSON string that do the work:

String DT_MAPPING = "{" +
" "mytype": {" +
" "dynamic_templates": [{" +
" "list_mapping": {" +
" "match":"list__"," +
" "mapping":{" +
" "index" : "not_analyzed"" +
" }" +
" }" +
" }, {" +
" "set_mapping": {" +
" "match":"set__
"," +
" "mapping":{" +
" "index" : "not_analyzed"" +
" }" +
" }" +
" }]" +
" }" +
"}";

On Tue, Nov 1, 2011 at 10:57 AM, Bojidar Penchev dcodeboy@gmail.com wrote:

Unfortunately the problem is not with the bracket in line 37.
I tried without the brackets but , then I got exception related to the
parsing of the JSON.
And also the same JSON string works fine with curl.

I think the problem is with the Java command, maybe I don't send the JSON
mapping in right way, or maybe it's a bug.

On Mon, Oct 31, 2011 at 11:50 PM, K.B. korbinian.bachl@googlemail.comwrote:

Didn't try out the code, but the bracket in line 37 seems wrong IMHO;

Best Regards

On 31 Okt., 22:05, Bojidar Penchev dcode...@gmail.com wrote:

Hi,

I'm facing a problem with the dynamic templates when I try to set them
using the Java API.

When I'm using the following curl command everything is fine.

curl -X POST "http://localhost:9200/myindex" -d '{
"mappings" : {
"mytype": {
"dynamic_templates":[{
"list_mapping": {
"match":"list__",
"mapping":{
"index" : "not_analyzed"
}
}
},{
"set_mapping": {
"match":"set__
",
"mapping":{
"index" : "not_analyzed"
}
}
}
]
}
}

}'

I tried to do the same in various ways using Java, but non of them was
successful.
Here is a gist https://gist.github.com/1328836with my initial guess in
Java.

If you run it, the output will be "{"mytype":{"properties":{}}}" , but
this
is obviously wrong, and If I try to index some documents with field
names
matching list__* or set__* they will be analyzed.
On the other side with the curl command everything works great.