3

I have 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' },
      }
    }
  }
}

Document look like this:

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

But I want store documents in this format:

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

Is there any way to do mapping for this? Or I should create only object 'shops' and keep it schema-less.

4
  • What kind of queries are you planning to do? Commented Apr 12, 2012 at 18:40
  • Queries will be simple, in most cases string queries for select products for specific shop. For example: { "query_string" : { "query" : "exists:shops.amazon.url" } } I prefer to store shops as object rather than array, because of easier manipulation in ruby. Commented Apr 12, 2012 at 22:06
  • @mrazicz did you mange to overcome this? Commented Mar 20, 2016 at 9:33
  • Hi, yeah, I use solution from answer below. But after all, I ended up with my original solution. Turns out, that array of objects is better for my use case. Commented Mar 30, 2016 at 7:28

1 Answer 1

2

You may be able to use a dynamic_template with a path_match ("shops.*") [1].

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

Sign up to request clarification or add additional context in comments.

4 Comments

This could be works. But now, how can I check if templates work? any suggestions?
Just add the documents, then retrieve the mapping.
@ejain - can you share your es mapping for this example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.