如何在搜索查询中加入文档

问题描述 投票:0回答:1
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 3,
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "product_index",
        "_type": "product",
        "_id": "1115",
        "_score": 0.2876821,
        "_source": {
          "isactive": true,
          "in_use": false,
          "brand_name": "Adidas",
          "sku_id": "56456487987987",
          "long_description": "this is long description",
          "key_feature": [
            {
              "id": 1148,
              "key_feature": "sport wear"
            },
            {
              "id": 1147,
              "key_feature": "Cotton shirt"
            },
            {
              "id": 1146,
              "key_feature": "White and blue"
            }
          ],
          "isdeleted": false,
          "created_by": null,
          "brand_id": 5,
          "search_terms": [
            {
              "label": "white shirt",
              "value": 9
            }
          ]
          "color_id": 2,
          "specific_keywords": "",
          "item_list": [
            {
              "item_id": 1114,
              "product_id": 1115,
              "isactive": true,
              "id": 9,
              "isdeleted": false
            },
            {
              "item_id": 1113,
              "product_id": 1115,
              "isactive": true,
              "id": 10,
              "isdeleted": false
            }
          ],
          "upc_code": "",
          "display_size": "L",
          "name": "New White shirt",
          "updated_by": null,
          "id": 1115,
          "updated_date": "2020-03-25T08:24:37.644571+00:00",
          "color_name": "blue",
          "created_date": "2020-03-25T08:11:14.966673+00:00",
          "category": [
            {
              "parent_category_id": 78,
              "sub_sub_category": null,
              "sub_category": null,
              "sub_category_id": null,
              "sub_sub_category_id": null,
              "parent_category": "new Shirt Cate",
              "id": 1151
            }
          ]
        }
      },
      {
        "_index": "product_index",
        "_type": "product",
        "_id": "1113",
        "_score": 0.2876821,
        "_source": {
          "isactive": true,
          "in_use": false,
          "sku_id": "1456456488",
          "brand_name": "Adidas",
          "long_description": "",
          "key_feature": [
            {
              "id": 1142,
              "key_feature": "Cotton"
            },
            {
              "id": 1141,
              "key_feature": "Office Use"
            },
            {
              "id": 1140,
              "key_feature": "Black formal"
            }
          ],
          "isdeleted": false,
          "created_by": null,
          "brand_id": 5,
          "search_terms": [

          ]
          "color_id": 1,
          "specific_keywords": "",
          "item_list": [

          ],
          "display_size": "L",
          "upc_code": "",
          "name": "New Cotton formal shirt black",
          "updated_by": null,
          "id": 1113,
          "updated_date": "2020-03-25T06:48:30.903041+00:00",
          "created_date": "2020-03-25T06:48:29.943043+00:00",
          "color_name": "black",
          "category": [
            {
              "sub_sub_category": null,
              "parent_category_id": 54,
              "sub_category": null,
              "sub_category_id": null,
              "sub_sub_category_id": null,
              "parent_category": "MEN'S CLOTHING",
              "id": 1149
            }
          ]
        }
      },
      {
        "_index": "product_index",
        "_type": "product",
        "_id": "1114",
        "_score": 0.2876821,
        "_source": {
          "isactive": true,
          "in_use": false,
          "sku_id": "145645648811",
          "brand_name": "Adidas",
          "long_description": "",
          "key_feature": [
            {
              "id": 1145,
              "key_feature": "Cotton"
            },
            {
              "id": 1144,
              "key_feature": "Office Use"
            },
            {
              "id": 1143,
              "key_feature": "Black formal"
            }
          ],
          "isdeleted": false,
          "created_by": null,
          "brand_id": 5,
          "search_terms": [

          ],
          "color_id": 1,
          "specific_keywords": "",
          "item_list": [

          ],
          "display_size": "L",
          "upc_code": "",
          "updated_by": null,
          "name": "New Cotton Casual shirt black",
          "id": 1114,
          "created_date": "2020-03-25T07:13:26.233675+00:00",
          "color_name": "black",
          "updated_date": "2020-03-25T07:13:27.229363+00:00",
          "category": [
            {
              "sub_sub_category": null,
              "parent_category_id": 54,
              "sub_category": null,
              "sub_category_id": null,
              "sub_sub_category_id": null,
              "parent_category": "MEN'S CLOTHING",
              "id": 1150
            }
          ]
        }
      }
    ]
  }
}

我的要求是将所有相关文档附加有特定的键值字段,这些字段在item_list中基于item_id指定。在上述结果中,文档ID 1115具有item_list,其中包含item_id 1114和1113。因此,特定字段附加在文档1115中。弹性搜索中的搜索查询应该是什么?

python elasticsearch django-rest-framework
1个回答
0
投票

您无法加入Elasticsearch,要实现目标,您可以做两件事:

  1. 复制item_id中的item_id 1114和1113的信息1115(当然,在所有其他文档中)。
  2. 请在应用程序级别加入,因此在此查询之后,您可以提取item_id 1114和1113并运行其他两个查询以获取有关此项目的信息。然后在应用程序级别加入所有json。
© www.soinside.com 2019 - 2024. All rights reserved.