数组中的 Elasticsearch 查询匹配

Elasticsearch query match in array

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的yield,我想过滤一下,比如productCategories te category Sports ones里面的名字,这个query怎么写

我用的是c#ta nest库

我不知道如何在你的库中做到这一点,但在 elasticsearch 中:

productCategories 必须映射为“嵌套”数据类型。 然后你将能够构建这样的查询:

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