elasticsearch查询匹配

vatpfxk5  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(1)|浏览(354)
id: 1,
name: "Jean Pantalon",
title: null,
subtitle: null,
description: null,
tags: null,
seoUrl: null,
clickCounter: 0,
model: null,
sku: null,
ean: null,
displayPrice: 0,
price: 0,
isActive: true,
isDeleted: false,
productPhotos: null,
productCategories: [
  {
    id: 1,
    productId: 1,
    categoryId: 2,
    category: {
       id: 2,
       name: "Spor",
       topCategoryId: 0,
       subCategories: null
       }
    },
 ]

大家好,elasticseaarch有这样一个json输出,我想对它进行过滤,比如productcategories te categories sports ones中的名称,如何编写这个查询
我在用c#ta nest图书馆

sqougxex

sqougxex1#

我不知道如何在lib中执行,但在elasticsearch中:
productcategories必须Map为“嵌套”数据类型。然后您将能够构造如下查询:

GET /my-index/_search
{
  "query": {
    "nested": {
      "path": "productCategories",
      "query": {
        "bool": {
          "must": [
            { "match": { "productCategories.category.name": "sport" } }
          ]
        }
      }
    }
  }
}

相关问题