我有一个产品-商家映射,如下所示
catalog_map = {
"catalog": {
"properties": {
"merchant_id": {
"type": "string",
},
"products": {
"type": "object",
},
"merchant_name" :{
"type" : "string"
}
}
}
}
“产品”具有对象,例如 product_id 、 product_name 、 product_price 。产品和商家被映射,这样:
for merchant in Merchant.objects.all() :
products = [{"product_name" : x.product.name, "product_price" : x.price, "product_id" : x.product.id , "product_category" : x.product.category.name} for x in MerchantProductMapping.objects.filter(merchant=merchant)]
tab = {
'merchant_id': merchant.id,
'merchant_name': merchant.name,
'product': products
}
res = es.index(index="my-index", doc_type='catalog', body=tab)
数据以所需的形式顺利索引。现在,当我从给定索引查询数据时,我按以下方式进行:
GET /esearch-index/catalog/_search
{
"query": {
"bool" :{
"must": [
{"match": {
"merchant_name": {
"query": "Sir John"
}
}}],
"should": [
{"match": {
"product_name": {
"query": "Vanilla"
}
}}
]
}}
此查询为我提供了索引中商家名称为 "Sir John" 的所有产品的结果。但是,我希望它返回“约翰爵士”出售的产品“香草”的详细信息。
根据某人的建议,我在查询时使用了“_source”,但这并没有帮助。
如何从商家的整个“目录”索引中挑出单个对象的信息?