Dynamic mappings using dynamic templates

Hi,

I am trying to use dynamic mapping where I want to use dynamic templates.

But it looks that if I have dynamic field name and value name , ES doesn't
create the mapping for this. It works when I have field as String, Number.
A problem is coming when I have field like json object (example: field
details)

{

"id": "abcd",

"details: {

"description": "text",

"number": 123

}

}

What I'm doing is:

/Step1
//I'm creating the index with the
settings:

//
*********************

$ curl -XPOST "http://localhost:9200/nicka/" -d'

{

"settings":{

"number_of_shards":3,

"number_of_replicas":1

,"more":{},

"index" : {

"analysis" : {

"analyzer" : {

"autocomplete" : {

"tokenizer" : "whitespace",

"filter" : ["lowercase", "engram"]

}

},

"filter" : {

"engram" : {

"type" : "edgeNGram",

"min_gram" : 3,

"max_gram" : 10

}

}

}

}

}

}'

//Step2
//Define mapping:
//
*********************************************************

$ curl -XPOST "http://localhost:9200/nicka/items/_mapping" -d'

{

"items" : {

"dynamic_templates" : [

    {

        "template_level_0" :{

            "match" : "id*",

            "match_mapping_type" : "string",

            "mapping" : {

                "type" : "string",

                "index" : "not_analyzed"

            }

        }

    },

    {

        "template_level_1" : {

"match" : "*",

"mapping" : {

"type" : "multi_field",

"fields" : {

"{name}" : {

            "type" : "{dynamic_type}",

            "index" : "analyzed",

            "store": "yes",

            "index_analyzer" : "autocomplete",

            "search_analyzer" : "standard"

},

"original":{"type" : "string", "index":"not_analyzed"}

}

}

}

    }

]

}

}'

/********Step3
//***************Create document:


//**************************************************************************

$ curl -XPUT "http://localhost:9200/nicka/items/1" -d'

{

"id" : "123-324-abcde",

  "number" : 1 234567,

"details" : {

 "description" : "some example text for document",

  "name" : "document 1",

  "number" : 1234567,

  "driver" : "John Smith"

},

"tags" : ["document", "driver", "car"]

}'

{"ok":true,"_index":"nicka","_type":"items","_id":"1","_version":1}

  1. PROBLEM: When I am checking the mapping I have result this:

$ curl -XGET "http://localhost:9200/nicka/items/_mapping?pretty"

{

"items" : {

"dynamic_templates" : [ {

  "template_level_0" : {

    "mapping" : {

      "type" : "string",

      "index" : "not_analyzed"

    },

    "match" : "id*",

    "match_mapping_type" : "string"

  }

}, {

  "template_level_1" : {

    "mapping" : {

      "type" : "multi_field",

      "fields" : {

        "{name}" : {

          "type" : "{dynamic_type}",

          "index" : "analyzed",

          "store" : "yes",

          "index_analyzer" : "autocomplete",

          "search_analyzer" : "standard"

        },

        "original" : {

          "type" : "string",

          "index" : "not_analyzed"

        }

      }

    },

    "match" : "*"

  }

} ],

"properties" : { }

}

}

As you see the properties is empty so it is not correct. When I'm create
simple document key-value I am able to see all mapping for these
relationships in this place: "properties".

/********Step4
//***************Search for test:


//**************************************************************************

When I'm trying to finde documet using filed: details.name I got correct
result:

$ curl -XGET "http://localhost:9200/nicka/items/_search?pretty" -d '

{

"query" : {

"term" : { "details.name" : "document" }

}

}'

{

"took" : 1,

"timed_out" : false,

"_shards" : {

"total" : 3,

"successful" : 3,

"failed" : 0

},

"hits" : {

"total" : 1,

"max_score" : 0.30685282,

"hits" : [ {

  "_index" : "nicka",

  "_type" : "items",

  "_id" : "1",

  "_score" : 0.30685282, "_source" :

{

"id" : "123-324-abcde",

"details" : {

 "description" : "some example text for document",

 "name" : "document",

 "number" : 1234567,

 "driver" : "Nicka"

},

"tags" : ["document", "driver", "car"]

}

} ]

}

}

Could you check this and tell me why I have this error?
If I wrote something what is not clear, please let me know. I will try to
explain more.

Thanks a lot!
Nicka

--
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/652c9f1d-80e6-437c-8720-68759e9282ca%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Nicka,
I want to perform dynamic mapping with three level nested data but I am not able to get.If you knows about that then please help me.I am sending my mapping file and data.so In this way i am not able to get the correct mapping.help me to putting the correct mapping with my data.
INDEX:

PUT /icd10_codes1
{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
}

MAPPING:

PUT /icd10_codes1/_mapping/my_type
{
"properties": {
"name": {
"type": "string",
"analyzer": "autocomplete"
},
"depth":{
"type":"long"
},
"dynamic_templates": [{
"nested_children": {
"match": "children",
"match_mapping_type": "string",
"mapping": {
"index": "analyzed",
"analyzer": "autocomplete"
}
}
}],
"dynamic_templates": [{
"nested_children.children": {
"match": "children.children",
"match_mapping_type": "string",
"mapping": {
"index": "analyzed",
"analyzer": "autocomplete"
}
}
}],
"dynamic_templates": [{
"nested_children.children.children": {
"match": "children.children.children",
"match_mapping_type": "string",
"mapping": {
"index": "analyzed",
"analyzer": "autocomplete"
}
}
}]

  }
}

DATA:

POST /icd10_codes1/my_type/1
{
"name": "Diseases of the blood and blood-forming organs and certain disorders involving the immune mechanism (D50-D89)",
"depth": 1,
"children": [{
"name": "Nutritional anemias (D50-D53)",
"depth": 2,
"children": [{
"code": "D50",
"name": "Iron deficiency anemia",
"depth": 3,
"children": [{
"code": "D50.0",
"name": "Iron deficiency anemia secondary to blood loss (chronic)",
"depth": 4
}, {
"code": "D50.1",
"name": "Sideropenic dysphagia",
"depth": 4
}, {
"code": "D50.8",
"name": "Other iron deficiency anemias",
"depth": 4
}, {
"code": "D50.9",
"name": "Iron deficiency anemia, unspecified",
"depth": 4
}]
}]
}]
}