Quantcast

Apply dynamic template to all fields of an object

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Apply dynamic template to all fields of an object

mkleen
Hello, 

I am trying to apply a dynamic template mapping to all fields of an object including the aggregated objects, but it gets only applied to the fields of the root object: 

 curl -XPUT http://localhost:9200/test/data/_mapping -d '{
    "_default_" : {        
      "dynamic_templates" : [           
           {
           "string_template" : {
               "match" : "*",
               "match_mapping_type" : "string",
               "mapping" : {
                   "type"   : "multi_field",
                   "fields" : {
                       "{name}"            : {"type": "string", "index" : "analyzed", "analyzer" : "default", "store" : "false",  "include_in_all": "true"},
                       "{name}_untouched"  : {"type": "string", "index" : "analyzed", "analyzer" : "simple", "store" : "false",  "include_in_all": "true"}                                                                                                                                                                              
                   }
               }
           }
         }                                                         
       ]
    }        
 }'

When I now add an object: 

 curl -XPUT http://localhost:9200/test/data/1 -d '{
     "name" : "michael",
     "company" : {
       name: "foobar"
     }
 }'
 
I can only query the fields of the root object with the _untouched postfix: 

curl -XGET http://localhost:9200/test/data/_search -d '{
    "query" : {
        "term" : { "name_untouched": "michael" }
    }
}'

but it doesnt get applied to company: 

curl -XGET http://localhost:9200/test/data/_search -d '{
    "query" : {
        "term" : { "company.name_untouched": "foobar" }
    }
}'

Is this feature not supported, or do I do something wrong ? 

Many Thanks,

Michael 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apply dynamic template to all fields of an object

kimchy
Administrator
You set the mapping wrongly, you set the _mapping on the data mapping, but then specify _default_ there. Here is a gist for both options, either directly on data, or setting it in a generic fashion on _default_: https://gist.github.com/2898285.

On Mon, Jun 4, 2012 at 4:52 PM, mkleen <[hidden email]> wrote:
Hello, 

I am trying to apply a dynamic template mapping to all fields of an object including the aggregated objects, but it gets only applied to the fields of the root object: 

    "_default_" : {        
      "dynamic_templates" : [           
           {
           "string_template" : {
               "match" : "*",
               "match_mapping_type" : "string",
               "mapping" : {
                   "type"   : "multi_field",
                   "fields" : {
                       "{name}"            : {"type": "string", "index" : "analyzed", "analyzer" : "default", "store" : "false",  "include_in_all": "true"},
                       "{name}_untouched"  : {"type": "string", "index" : "analyzed", "analyzer" : "simple", "store" : "false",  "include_in_all": "true"}                                                                                                                                                                              
                   }
               }
           }
         }                                                         
       ]
    }        
 }'

When I now add an object: 

     "name" : "michael",
     "company" : {
       name: "foobar"
     }
 }'
 
I can only query the fields of the root object with the _untouched postfix: 

    "query" : {
        "term" : { "name_untouched": "michael" }
    }
}'

but it doesnt get applied to company: 

    "query" : {
        "term" : { "company.name_untouched": "foobar" }
    }
}'

Is this feature not supported, or do I do something wrong ? 

Many Thanks,

Michael 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apply dynamic template to all fields of an object

mkleen
Ok thanks. One more questions: 

curl -XPUT http://localhost:9200/test -d '{
  "mappings" : {

Which equivalent request is that in the java api ? It doesnt look like a mapping request.

Many thanks,

Michael


curl -XPUT http://localhost:9200/test/_default_/_mapping -d '{

On Saturday, June 9, 2012 12:02:31 AM UTC+2, kimchy wrote:
You set the mapping wrongly, you set the _mapping on the data mapping, but then specify _default_ there. Here is a gist for both options, either directly on data, or setting it in a generic fashion on _default_: https://gist.github.com/2898285.

On Mon, Jun 4, 2012 at 4:52 PM, mkleen <[hidden email]> wrote:
Hello, 

I am trying to apply a dynamic template mapping to all fields of an object including the aggregated objects, but it gets only applied to the fields of the root object: 

    "_default_" : {        
      "dynamic_templates" : [           
           {
           "string_template" : {
               "match" : "*",
               "match_mapping_type" : "string",
               "mapping" : {
                   "type"   : "multi_field",
                   "fields" : {
                       "{name}"            : {"type": "string", "index" : "analyzed", "analyzer" : "default", "store" : "false",  "include_in_all": "true"},
                       "{name}_untouched"  : {"type": "string", "index" : "analyzed", "analyzer" : "simple", "store" : "false",  "include_in_all": "true"}                                                                                                                                                                              
                   }
               }
           }
         }                                                         
       ]
    }        
 }'

When I now add an object: 

     "name" : "michael",
     "company" : {
       name: "foobar"
     }
 }'
 
I can only query the fields of the root object with the _untouched postfix: 

    "query" : {
        "term" : { "name_untouched": "michael" }
    }
}'

but it doesnt get applied to company: 

    "query" : {
        "term" : { "company.name_untouched": "foobar" }
    }
}'

Is this feature not supported, or do I do something wrong ? 

Many Thanks,

Michael 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apply dynamic template to all fields of an object

Michael Kleen
In reply to this post by kimchy
Thanks for you answer. It still doesnt work, i tried the following setup: 

https://gist.github.com/2922822

Thanks for your time, 

Michael

On Saturday, June 9, 2012 12:02:31 AM UTC+2, kimchy wrote:
You set the mapping wrongly, you set the _mapping on the data mapping, but then specify _default_ there. Here is a gist for both options, either directly on data, or setting it in a generic fashion on _default_: https://gist.github.com/2898285.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apply dynamic template to all fields of an object

kimchy
Administrator
It should be company.name.untouched, not with an underscore.

On Wed, Jun 13, 2012 at 10:41 AM, Michael Kleen <[hidden email]> wrote:
Thanks for you answer. It still doesnt work, i tried the following setup: 


Thanks for your time, 

Michael

On Saturday, June 9, 2012 12:02:31 AM UTC+2, kimchy wrote:
You set the mapping wrongly, you set the _mapping on the data mapping, but then specify _default_ there. Here is a gist for both options, either directly on data, or setting it in a generic fashion on _default_: https://gist.github.com/2898285.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apply dynamic template to all fields of an object

Michael Kleen
I tried that as well, it doesnt make a difference. There most be something wrong in the configuration which i cannot see. I updated the gist including the server responses  https://gist.github.com/2922822

I do get results for 
{
"query" : {
         "term" : { "name.untouched": "michael" }
     }
}

and for: 

{
"query" : {
         "term" : { "company.name": "foobar" }
     }
}

but not for 

{
"query" : {
         "term" : { "company.name.untouched": "foobar" }
     }
}

Thanks for your time, 

Michael




On Thursday, June 14, 2012 11:08:41 PM UTC+2, kimchy wrote:
It should be company.name.untouched, not with an underscore.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apply dynamic template to all fields of an object

Igor Motov-3
In your example, untouched company name is indexed as "company.name.name.untouched" not as "company.name.untouched". Try deleting your mapping and recreating it like this:

curl -XPUT http://localhost:9200/test/data/_mapping -d '{
    "data" : {        
      "dynamic_templates" : [           
           {
           "string_template" : {
               "match" : "*",
               "match_mapping_type" : "string",
               "mapping" : {
                   "type"   : "multi_field",
                   "fields" : {
                       "{name}"            : {"type": "string", "index" : "analyzed", "analyzer" : "default", "store" : "false"},
                       "untouched"  : {"type": "string", "index" : "analyzed", "analyzer" : "default", "store" : "false"}                                                                                                                                                                              
                   }
               }
           }
         }                                                         
       ]
    }        
 }'

On Friday, June 15, 2012 4:13:28 AM UTC-4, Michael Kleen wrote:
I tried that as well, it doesnt make a difference. There most be something wrong in the configuration which i cannot see. I updated the gist including the server responses  https://gist.github.com/2922822

I do get results for 
{
"query" : {
         "term" : { "name.untouched": "michael" }
     }
}

and for: 

{
"query" : {
         "term" : { "company.name": "foobar" }
     }
}

but not for 

{
"query" : {
         "term" : { "company.name.untouched": "foobar" }
     }
}

Thanks for your time, 

Michael




On Thursday, June 14, 2012 11:08:41 PM UTC+2, kimchy wrote:
It should be company.name.untouched, not with an underscore.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apply dynamic template to all fields of an object

Michael Kleen
rocknroll, its all working now. thank you so much for pointing that out! 

Michael 

Loading...