首页 > 解决方案 > 在 ES 查询过滤器上使用 match_phrase 两次?没有为 [match_phrase] 注册过滤器

问题描述

我一直在尝试使用多个过滤器获取文档。

我目前正在使用 ES 1.7 是否可以match_phrase在过滤器上使用两次?

示例:人员文档 q=aaron&address=scarborough- 按姓名和地址搜索人员,效果很好。

{
  "query": {
    "match_phrase": {
      "name": "aaron"
    }
  },
  "filter": {
    "bool": {
      "must": {
        "nested": {
          "path": "addresses",
          "query": {
            "match_phrase": {
              "address": "scarborough"
            }
          }
        }
      }
    }
  },

q=aaron&phone=813-689-6889- 通过姓名和电话号码搜索一个人也可以正常工作。

{
  "query": {
    "match_phrase": {
      "name": "aaron"
    }
  },
  "filter": {
    "bool": {
      "must": {
        "query": {
          "match_phrase": {
            "phone": "813-689-6889"
          }
        }
      }
    }
  }

但是,当我尝试同时使用过滤器、地址和电话时出现No filter registered for [match_phrase]错误

例如:q=aaron&address=scarborough&phone=813-689-6889

{
  "query": {
    "match_phrase": {
      "name": "aaron"
    }
  },
  "filter": {
    "bool": {
      "must": {
        "nested": {
          "path": "addresses",
          "query": {
            "match_phrase": {
              "address": "scarborough"
            }
          }
        },
        "query": {
          "match_phrase": {
            "phone": "813-689-6889"
          }
        }
      }
    }
  }

一起使用addressphone过滤器时的错误:

nested: QueryParsingException[[pl_people] No filter registered for [match_phrase]]; }]","status":400}):

索引映射(人)按要求:

{
  "pl_people": {
    "mappings": {
      "person": {
        "properties": {
          "ac_name": {
            "type": "string",
            "analyzer": "autocomplete"
          },
          "date_of_birth": {
            "type": "date",
            "format": "dateOptionalTime"
          },
          "email": {
            "type": "string"
          },
          "first_name": {
            "type": "string",
            "fields": {
              "na_first_name": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "last_name": {
            "type": "string",
            "fields": {
              "na_last_name": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "middle_name": {
            "type": "string",
            "fields": {
              "na_middle_name": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "name": {
            "type": "string",
            "fields": {
              "na_name": {
                "type": "string",
                "index": "not_analyzed"
              },
              "ngram_name": {
                "type": "string",
                "analyzer": "my_start"
              },
              "ns_name": {
                "type": "string",
                "analyzer": "no_stopwords"
              }
            }
          },
          "phone": {
            "type": "string"
          },
          "time": {
            "type": "date",
            "format": "dateOptionalTime"
          },
          "updated_at": {
            "type": "date",
            "format": "dateOptionalTime"
          }
        }
      }
    }
  }
}

标签: elasticsearchjbuilder

解决方案


也许您可以使用 term-filter,而不是 match_phrase 作为过滤器。

这里


推荐阅读