首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ES查询筛选器上使用match_phrase两次?没有为[match_phrase]注册筛选器

在ES查询筛选器上使用match_phrase两次?没有为[match_phrase]注册筛选器
EN

Stack Overflow用户
提问于 2020-03-04 02:21:18
回答 1查看 60关注 0票数 0

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

我目前使用的是ES 1.7,是否可以在一个过滤器上使用两次match_phrase

示例: people document q=aaron&address=scarborough -根据姓名和地址搜索一个人,效果很好。

代码语言:javascript
复制
{
  "query": {
    "match_phrase": {
      "name": "aaron"
    }
  },
  "filter": {
    "bool": {
      "must": {
        "nested": {
          "path": "addresses",
          "query": {
            "match_phrase": {
              "address": "scarborough"
            }
          }
        }
      }
    }
  },

q=aaron&phone=813-689-6889 -通过姓名和电话号码搜索一个人也很好。

代码语言:javascript
复制
{
  "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

代码语言:javascript
复制
{
  "query": {
    "match_phrase": {
      "name": "aaron"
    }
  },
  "filter": {
    "bool": {
      "must": {
        "nested": {
          "path": "addresses",
          "query": {
            "match_phrase": {
              "address": "scarborough"
            }
          }
        },
        "query": {
          "match_phrase": {
            "phone": "813-689-6889"
          }
        }
      }
    }
  }

同时使用addressphone筛选器时出现以下错误:

代码语言:javascript
复制
nested: QueryParsingException[[pl_people] No filter registered for [match_phrase]]; }]","status":400}):

请求的索引映射(person):

代码语言:javascript
复制
{
  "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"
          }
        }
      }
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2020-03-04 03:13:08

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

参见here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60513379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档