0

您好我正在构建一个弹性搜索查询来在根文档和嵌套文档之间进行关键字搜索,并且我需要为嵌套和根文档提供过滤和聚合功能。这是我正在使用的查询。我遇到了麻烦:

  1. 无法为嵌套类型应用多个过滤器。(我可以为根文档应用多重过滤器)。
  2. 无法将嵌套类型的多重过滤器转换为 Java 代码。(不确定要为“查询”部分使用哪个类 - MatchQueryBuilder 还是 NestedQueryBuilder?
            "bool":  {
              "filter": {
                "nested": {
                  "path": "items",
                  "query": [
                    {
                      "match": {
                        "items.attributes.color.color.colorDescription": "Gray"
                      }
                    }
                  ]
               }
            }
          }

弹性搜索专家,请帮助我!谢谢!

{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "query_string": {
                  "query": "cuce",
                  "default_field": "*",
                  "fields": [],
                  "type": "best_fields",
                  "default_operator": "and"
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "query_string": {
                        "query": "cuce",
                        "default_field": "*",
                        "fields": [],
                        "type": "best_fields",
                        "default_operator": "and"
                      }
                    },
                    {
                      "nested": {
                        "query": {
                          "bool": {
                            "should": [
                              {
                                "multi_match": {
                                  "query": "cuce",
                                  "fields": [
                                    "items.attributes.color.color.colorDescription^1.0",
                                    "items.attributes.color.colorFamily^1.0"
                                  ],
                                  "type": "best_fields",
                                  "operator": "OR"
                                }
                              }
                            ]
                          }
                        },
                        "path": "items",
                        "score_mode": "max",
                        "inner_hits": {}
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ],
      "filter": [
        {
          "term": {
            "attributes.ageGroup.keyword": "ADULT"
           }
          },
          {
          "term": {
            "attributes.gender.keyword": "FEMALE"
           }
          },
          {
            "bool":  {
              "filter": {
                "nested": {
                  "path": "items",
                  "query": [
                    {
                      "match": {
                        "items.attributes.color.color.colorDescription": "Gray"
                      }
                    }
                  ]
               }
            }
          }
        }
      ]
    }
  },
   "aggregations": {
            "attributes.ageGroup": {
                "terms": {
                    "field": "attributes.ageGroup.keyword",
                    "size": 10,
                    "min_doc_count": 1,
                    "shard_min_doc_count": 0,
                    "show_term_doc_count_error": false,
                    "order": [
                        {
                            "_count": "desc"
                        },
                        {
                            "_key": "asc"
                        }
                    ]
                }
            },
            "attributes.gender": {
                "terms": {
                    "field": "attributes.gender.keyword",
                    "size": 10,
                    "min_doc_count": 1,
                    "shard_min_doc_count": 0,
                    "show_term_doc_count_error": false,
                    "order": [
                        {
                            "_count": "desc"
                        },
                        {
                            "_key": "asc"
                        }
                    ]
                }
            },
             "items.attributes.nationalRetailFederationAttributes.nrfColorCode": {
                "nested": {
                    "path": "items"
                },
                "aggregations": {
                    "items.attributes.nationalRetailFederationAttributes.nrfColorCode": {
                        "terms": {
                            "field": "items.attributes.nationalRetailFederationAttributes.nrfColorCode.keyword",
                            "size": 10,
                            "min_doc_count": 1,
                            "shard_min_doc_count": 0,
                            "show_term_doc_count_error": false,
                            "order": [
                                {
                                    "_count": "desc"
                                },
                                {
                                    "_key": "asc"
                                }
                            ]
                        }
                    }
                }
            },
            "items.attributes.nationalRetailFederationAttributes.nrfSizeLabel": {
                "nested": {
                    "path": "items"
                },
                "aggregations": {
                    "items.attributes.nationalRetailFederationAttributes.nrfSizeLabel": {
                        "terms": {
                            "field": "items.attributes.nationalRetailFederationAttributes.nrfSizeLabel.keyword",
                            "size": 10,
                            "min_doc_count": 1,
                            "shard_min_doc_count": 0,
                            "show_term_doc_count_error": false,
                            "order": [
                                {
                                    "_count": "desc"
                                },
                                {
                                    "_key": "asc"
                                }
                            ]
                        }
                    }
                }
            }
        }
}
4

0 回答 0