代码之家  ›  专栏  ›  技术社区  ›  JohnBigs

我的短语前缀查询不适用于数值

  •  2
  • JohnBigs  · 技术社区  · 8 年前

    我的问题很简单,如下所示:

    {
      "query": {
        "bool": {
          "should": [
            {
              "multi_match": {
                "query": "something_to_search",
                "type": "phrase_prefix",
                "fields": [
                  "name",
                  "id"
                  ...
                ],
                "lenient": true
              }
            }
          ],
          "minimum_should_match": 1,
          "boost": 1.0
        }
      }
    }
    

    name 是文本值和 id 是数值,如果我搜索“Jo”,我会得到名字以“Jo”开头的人,但是如果我搜索“123”,我不会得到id以“123”开头的人,但是如果我搜索确切的id,我会得到一个结果。

    有人能告诉我怎样才能得到数字的前缀查询吗?

    我的映射:

    {
      "people_db": {
        "mappings": {
          "person": {
            "properties": {
              "address": {
                "properties": {
                  "city": {
                    "type": "text",
                    "fields": {
                      "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                      }
                    }
                  },
                  "street": {
                    "type": "text",
                    "fields": {
                      "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                      }
                    }
                  },
                  "streetNumber": {
                    "type": "long"
                  },
                  "zipCode": {
                    "type": "long"
                  }
                }
              },
              "country": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "name": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "id": {
                "type": "long"
              }
            }
          }
        }
      }
    }
    
    0 回复  |  直到 8 年前