在弹性搜索中从嵌套文档中获取全部/等于

时间:2018-10-12 04:43:43

标签: elasticsearch-6

我要搜索所有等于的嵌套文档,我的弹性搜索映射如下所示

{
      "attribute_search_index": {
        "mappings": {
          "attribute_search": {
            "dynamic": "true",
            "properties": {
              "attrId": {
                "type": "text"
              },
              "attrName": {
                "type": "text"
              },
              "attributeChildData": {
                "type": "nested",
                "properties": {
                  "attributeChildId": {
                    "type": "integer"
                  },
                  "attributeChildTxt": {
                    "type": "text"
                  },
                  "attributeChild_responsible": {
                    "type": "nested",
                    "properties": {
                      "responsible_id": {
                        "type": "integer"
                      },
                      "responsible_name": {
                        "type": "text"
                      }
                    }
                  },
                  "attrId": {
                    "type": "integer"
                  }
                }
              },
              "attributePrj": {
                "type": "nested",
                "properties": {
                  "attributePrj_Id": {
                    "type": "integer"
                  },
                  "attributePrj_name": {
                    "type": "keyword"
                  }
                }
              }
            }
          }
        }
      }
    }

这是我的布尔查询

{
"query":{
  "bool" : {
    "must" : [
      {
        "nested" : {
          "query" : {
            "bool" : {
              "must" : [
                {
                  "match" : {
                    "attributePrj.name" : {
                      "attributePrj_name" : "PROJ 121",
                      "operator" : "OR",
                      "prefix_length" : 0,
                      "max_expansions" : 50,
                      "fuzzy_transpositions" : true,
                      "lenient" : false,
                      "zero_terms_query" : "NONE",
                      "auto_generate_synonyms_phrase_query" : true,
                      "boost" : 1.0
                    }
                  }
                }
              ],
              "adjust_pure_negative" : true,
              "boost" : 1.0
            }
          },
          "path" : "attributePrj",
          "ignore_unmapped" : false,
          "score_mode" : "avg",
          "boost" : 1.0
        }
      },
      {
        "nested" : {
          "query" : {
            "bool" : {
              "must" : [
                {
                  "match" : {
                    "attributeChildData.attributeChild_responsible.responsible_id" : {
                      "query" : "100",
                      "operator" : "OR",
                      "prefix_length" : 0,
                      "max_expansions" : 50,
                      "fuzzy_transpositions" : true,
                      "lenient" : false,
                      "zero_terms_query" : "NONE",
                      "auto_generate_synonyms_phrase_query" : true,
                      "boost" : 1.0
                    }
                  }
                }
              ],
              "adjust_pure_negative" : true,
              "boost" : 1.0
            }
          },
          "path" : "attributeChildData",
          "ignore_unmapped" : false,
          "score_mode" : "avg",
          "boost" : 1.0
        }
      }
    ],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}
}

这给了我一个嵌套的attributeChild_responsible.responsible_id是否等于“ 100”的信息,我正在查看该文档下所有嵌套的对象是否必须具有100,然后仅返回结果

0 个答案:

没有答案
相关问题