Mapping elasticsearch for an object with dynamic keys

I have a simple document with this mapping:

'product': {
  'properties': {
    'name': { 'type': 'string' },
    'shops': { 
      'type': 'object', 
      'index_name': 'shop', 
      'properties': {
        'name': { 'type': 'string' },
        'url': { 'type': 'string' },
        'price': { 'type': 'integer' },
      }
    }
  }
}

The document is as follows:

{ 
  'name': 'Kindle', 
  'shops': [ 
    { 'name': 'amazon', 'url': 'http://...', 'price': 79 },
    { 'name': 'ebay', 'url': 'http://...', 'price': 99 }
}

But I want to store documents in this format:

{
  'name': 'Kindle',
  'shops': {
    'amazon': { 'url': 'http://...', 'price': 79 },
    'ebay': { 'url': 'http://...', 'price': 99 }
  }
}

Is there a way to do a mapping for this? Or I have to create only objects "stores" and save them without a diagram.

+3
source share
1 answer

Perhaps you can use dynamic_template with path_match ("stores. *") [1].

[1] https://www.elastic.co/guide/en/elasticsearch/reference/1.4/mapping-root-object-type.html

+3
source

All Articles