elasticsearch 按嵌套字段值分隔从elastic返回的命中,elasticsearch,kibana,nest,elasticsearch,Kibana,Nest" /> elasticsearch 按嵌套字段值分隔从elastic返回的命中,elasticsearch,kibana,nest,elasticsearch,Kibana,Nest" />

elasticsearch 按嵌套字段值分隔从elastic返回的命中

elasticsearch 按嵌套字段值分隔从elastic返回的命中,elasticsearch,kibana,nest,elasticsearch,Kibana,Nest,我已经在那里建立了产品索引。我试图通过嵌套的字段值来区分从elastic返回的命中。这是我的缩短索引: { "mapping": { "product": { "properties": { "id": { "type": "integer" }, "model_name": { "type": "text", },

我已经在那里建立了产品索引。我试图通过嵌套的字段值来区分从elastic返回的命中。这是我的缩短索引:

{
  "mapping": {
    "product": {
      "properties": {        
        "id": {
          "type": "integer"
        },
        "model_name": {
          "type": "text",          
        },
        "variants": {
          "type": "nested",
          "properties": {
            "attributes": {
              "type": "nested",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "name": {
                  "type": "text"
                },
                "product_attribute_id": {
                  "type": "integer"
                },               
                "value": {
                  "type": "text"
                }
              }
            },
            "id": {
              "type": "integer"
            },
            "product_id": {
              "type": "integer"
            }            
          }
        }
      }
    }
  }
}
和产品示例(产品中有更多的变体和属性-我只是将它们删掉):

讨论中的字段是attribute id。假设我想按大小属性分隔产品-id 29。如果回答如下所示,那将是完美的:

"hits" : [
{
   "_index":"product_index",
   "_type":"product",
   "id":192,
   "model_name":"Some tshirt",
   "variants":[
      {
         "id":1271,
         "product_id":192,
         "attributes":[
            {
               "id":29,
               "name":"clothesSize",
               "value":"XL",
               "product_attribute_id":36740
            }
         ]
      }
   ]
},     
{
   "_index":"product_index",
   "_type":"product",
   "id":192,
   "model_name":"Some tshirt",
   "variants":[      
      {
         "id":1272,
         "product_id":192,
         "attributes":[
            {
               "id":29,
               "name":"clothesSize",
               "value":"L",
               "product_attribute_id":36741
            }
         ]
      }
   ]
}]
我曾考虑将弹性请求中的所有变量分开,然后根据这些属性在应用程序端对它们进行分组,但我认为这不是最优雅、最重要的、最有效的方法。
我应该感兴趣的弹性关键词是什么?

提前感谢您的帮助。

您可以获得嵌套的
内部搜索结果
(),然后使用
过滤器路径
减少只对您感兴趣的字段的响应()。请记住,在执行此操作时,您可能会将JSON简化为NEST的序列化程序无法反序列化的结构,因此可能需要使用低级客户端返回字符串,并将自己解析为
JObject
或类似的一般JSON结构。您可以获得嵌套的
内部\u命中()然后使用
filter\u path
减少只对您感兴趣的字段的响应()。请记住,在执行此操作时,可能会将JSON简化为NEST的序列化程序无法反序列化的结构,因此可能需要使用低级客户端返回字符串并将自己解析为
JObject
或类似的一般JSON结构
"hits" : [
{
   "_index":"product_index",
   "_type":"product",
   "id":192,
   "model_name":"Some tshirt",
   "variants":[
      {
         "id":1271,
         "product_id":192,
         "attributes":[
            {
               "id":29,
               "name":"clothesSize",
               "value":"XL",
               "product_attribute_id":36740
            }
         ]
      }
   ]
},     
{
   "_index":"product_index",
   "_type":"product",
   "id":192,
   "model_name":"Some tshirt",
   "variants":[      
      {
         "id":1272,
         "product_id":192,
         "attributes":[
            {
               "id":29,
               "name":"clothesSize",
               "value":"L",
               "product_attribute_id":36741
            }
         ]
      }
   ]
}]