簡體   English   中英

在 ES 查詢過濾器上使用 match_phrase 兩次? 沒有為 [match_phrase] 注冊過濾器

[英]using match_phrase twice on ES query filter? No filter registered for [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]錯誤未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"
          }
        }
      }
    }
  }
}

也許您可以使用 term-filter 而不是 match_phrase 作為過濾器。

這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM