1
votes

I'm trying to add dynamic templates. I've done

curl -XPUT 'localhost:9200/my_index_items?pretty' -H 'Content-Type: application/json' -d'
{
 "mappings": {
   "item": {
     "dynamic_templates": [
       {
         "sales_price_in_cent_as_long": {
           "match":   "sales_price_in_cent",
           "mapping": {
             "type": "long"
           }
         },
         "sales_price_formatted_as_double": {
           "match":   "sales_price_formatted",
           "mapping": {
             "type": "double"
           }
         },
         ...
       }
     ]
   }
 }
}
'

So in "my_index_items" i got the type "item", when I now index an item (item has a field "sales_price_formatted" which has a value like "12,34") and lookup with GET 'localhost:9200/my_index_items/item/_mapping' it shows the "sales_price_formatted" as of type "text" instead of "double".

Am I doing something wrong? I thought, if an item has a field which is defined in the "match" property in my dynamic templates, then it wouldn't use its own default mechanism but the one defined here?

1
If you do GET /my_index_items/item/_mapping do you see the dynamic templates defined in there? - Andrei Stefan
no, should I see the dynamic templates as well here? I just see the mappings elasticsearch has made after indexing one item. Here like described above "sales_price_formatted" as of type "text". - Leo

1 Answers

0
votes

You have some missing curly brackets in your command. It should be like this:

{
  "mappings": {
    "item": {
      "dynamic_templates": [
        {
          "sales_price_in_cent_as_long": {
            "match": "sales_price_in_cent",
            "mapping": {
              "type": "long"
            }
          }
        },
        {
          "sales_price_formatted_as_double": {
            "match": "sales_price_formatted",
            "mapping": {
              "type": "double"
            }
          }
        }
      ]
    }
  }
}