我有這個映射簡單的文檔:Elasticsearch映射與動態密鑰對象
'product': {
'properties': {
'name': { 'type': 'string' },
'shops': {
'type': 'object',
'index_name': 'shop',
'properties': {
'name': { 'type': 'string' },
'url': { 'type': 'string' },
'price': { 'type': 'integer' },
}
}
}
}
文件看起來像這樣:
{
'name': 'Kindle',
'shops': [
{ 'name': 'amazon', 'url': 'http://...', 'price': 79 },
{ 'name': 'ebay', 'url': 'http://...', 'price': 99 }
}
但我想以這種格式存儲文檔:
{
'name': 'Kindle',
'shops': {
'amazon': { 'url': 'http://...', 'price': 79 },
'ebay': { 'url': 'http://...', 'price': 99 }
}
}
有沒有什麼辦法可以做到這一點?或者我應該只創建對象'商店'並保持它無模式。
您打算做什麼樣的查詢? – ejain 2012-04-12 18:40:28
查詢將很簡單,在大多數情況下,針對特定商店的選定產品的字符串查詢。例如: { 「QUERY_STRING」:{ 「查詢」: 「_exists_:shops.amazon.url」 }} 我寧願店中店爲對象,而不是數組,因爲在Ruby更容易操縱。 – mrazicz 2012-04-12 22:06:56
@mrazicz你有沒有想過要克服這個問題? – 2016-03-20 09:33:45