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

时间:2018-07-29 08:26:06

标签: elasticsearch elasticsearch-5

我的查询非常简单,看起来像这样:

{
  "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 个答案:

没有答案