2014-10-08 3 views
0

У меня есть объект, как это в ES:Поиск хэш в массив

{ 
    _index: products_development_20141007185853021 
    _type: product 
    _id: 5039 
    _version: 1 
    _score: 1 
    _source: { 
    name: Le Moelleux - Gâ teau tout Chocolat 
    quantity: 500 
    quantity_unit: gram 
    store_ids: [ 
     503 
     504 
     505 
    ] 
    name_suggest: Le Moelleux - Gâ teau tout Chocolat 
    store_prices: [{ 
     id: 503 
     price: 2.65 
    } { 
     id: 504 
     price: 2.65 
    } { 
     id: 505 
     price: 2.65 
    } ] 
    product_categories: [{ 
     id: 109 
     name: Viennoiserie 
     parent: { 
     id: 105 
     name: Pain, 
     viennoiserie, 
     biscotte 
     parent_id: 92 
     tags: [ 
      pains et viennoiseries 
      biscotte 
      tartine 
      biscottes tartines 
      boulangerie 
      pâ tisseries moelleuses 
     ] 
     } 
    }] 
    product_brand: { 
     id: 1134 
     name: KER CADELAC 
     type: null 
    } 
    store_company: { 
     id: 4 
     name: Chronodrive 
    } 
    categories_and_ancestors: [{ 
     id: 109 
    } { 
     id: 105 
    } { 
     id: 92 
    }] 
    } 
} 

С помощью этого отображения:

mappings: { 
    product: { 
    properties: { 
     item_count: { 
     type: integer 
     } 
     name_suggest: { 
     search_analyzer: whitespace_analyzer 
     index_analyzer: nGram_analyzer 
     type: string 
     } 
     store_company: { 
     properties: { 
      name: { 
      type: string 
      } 
      id: { 
      type: long 
      } 
     } 
     } 
     quantity_unit: { 
     index: not_analyzed 
     type: string 
     } 
     quantity: { 
     type: double 
     } 
     store_ids: { 
     type: string 
     } 
     store_prices: { 
     properties: { 
      price: { 
      type: double 
      } 
      id: { 
      type: integer 
      } 
     } 
     } 
     categories_and_ancestors: { 
     properties: { 
      id: { 
      type: integer 
      } 
     } 
     } 
     product_categories: { 
     properties: { 
      parent: { 
      properties: { 
       parent_id: { 
       type: long 
       } 
       name: { 
       type: string 
       } 
       id: { 
       type: long 
       } 
       tags: { 
       type: string 
       } 
      } 
      } 
      name: { 
      type: string 
      } 
      id: { 
      type: integer 
      } 
     } 
     } 
     name: { 
     analyzer: product_analyzer 
     type: string 
     } 
     product_brand: { 
     properties: { 
      name: { 
      type: string 
      fields: { 
       raw: { 
       index: not_analyzed 
       type: string 
       } 
      } 
      } 
      id: { 
      type: integer 
      } 
      type: { 
      type: string 
      } 
     } 
     } 
    } 
    } 
} 

Как я могу сделать запрос или фильтр, чтобы получить все документы, где store_prices имеет не указано:

{ 
    id: 503 
    price: 0 
} 

Я имею в виду полный объект. Я хочу, чтобы перевести этот запрос в ES:

select from products where store_prices does not include { id: 503, price: 0 } 

поблагодарить вас

+0

Я не видя store_prices в вашем сопоставлении. –

+0

Oups, я не вставил хорошее картирование – Sebastien

ответ

1

Если вы хотите кортеж {ID: 503, цена: 0} не содержаться в этом массиве кортежей (и соответствующих целых кортежей , а не «id» из одного кортежа и «цена» от другого), тогда вы не можете. Вам нужны вложенные объекты. Лучшим объяснением этого является here, in the documentation.

Для того, чтобы работать вам нужно это отображение для цен на сырье:

"store_prices": { 
    "type": "nested", 
    "properties": { 
    "price": { 
     "type": "double" 
    }, 
    "id": { 
     "type": "integer" 
    } 
    } 
} 

И для запроса (фильтр) для отображения выше, вы бы использовать это:

{ 
    "query": { 
    "filtered": { 
     "filter": { 
     "bool": { 
      "must_not": [ 
      { 
       "nested": { 
       "path": "store_prices", 
       "query": { 
        "bool": { 
        "must": [ 
         { "match": {"store_prices.id": "503"}}, 
         { "match": {"store_prices.price": "2.65"}} 
        ] 
        }}}} 
      ]}}} 
    } 
} 
+0

Спасибо! Я жду, может быть, некоторые другие ответят, а затем примут ваше. – Sebastien

Смежные вопросы