Elasticsearch查询多个子字段

时间:2019-10-30 19:45:01

标签: elasticsearch

我很好奇是否有人知道如何查询Elasticsearch索引中的多个子字段。例如记录:

{
  "foo": [
    {
      "bar": "Good example",
      "subfield":  32
    }
  ]
},
{
  "foo": [
    {
      "bar": "Good example",
      "subfield":  50
    }
  ]
},
{
  "foo": [
    {
      "bar": "Bad example",
      "subfield":  32
    }
  ]
}

我希望构建仅返回第一条记录的查询foo.bar = "Good example" AND foo.subfield = 32。欢迎使用Elasticsearch的查询DSL或查询字符串。

1 个答案:

答案 0 :(得分:1)

您想要一个nested query

 # creat a workbook
 filena = "produitimage.xlsx"
 workbook = Workbook()
 sheet = workbook.active
 #add headers
 sheet.append(["Product ID", "Product Name", "Marque",
          "Category", "Family", "Photos"])
 for product in products:
    for item in product.items():
        for row, entry in enumerate(item, start=3):
            sheet.cell(row=row, column=1, value=entry)
 #add some images
 images = [item['photos'] for item in products]
 for image in images:
     logo = Image(image)
     #logo.height = 150
     #logo.width = 150
     sheet.add_image(logo)
 workbook.save(filename=filena)

请注意,根据文档,您必须更新映射以包括嵌套字段映射。