词组前缀查询不起作用

时间:2018-07-30 23:22:27

标签: elasticsearch elasticsearch-5 elasticsearch-plugin spring-data-elasticsearch elasticsearch-aggregation

我有一个简单的文档,可直接由mongodb插入,看起来像这样:

PUT /office_db/employee/1
{
  "employeeId": "5b5fc605357d0c6",
  "formalName": "mark rose",
  "socialNumber": 2147483647,
  "contact": {
    "name": "dave more",
    "email": "dave@gmail.com",
    "phone": 918493203
  }
}

我创建了一个多匹配查询来搜索3个字段:

GET /office_db/employee/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "214748364",
            "fields": [
              "formalName^-1.0",
              "socialNumber^-1.0",
              "contact.phone^-1.0"
            ],
            "type": "phrase_prefix",
            "lenient": "true"
          }
        }
      ]
    }
  }
}

我的问题是,如果我尝试搜索socialNumber的前缀,则只有在输入整数后才能得到结果,但我没有得到结果。但是,如果我搜索formalName的前缀,则会得到结果...由于字段类型而可能吗?

这是我的映射:

{
  "office_db": {
    "mappings": {
      "employee": {
        "properties": {
          "contact": {
            "properties": {
              "email": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "name": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "phone": {
                "type": "long"
              }
            }
          },
          "employeeId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "formalName": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "socialNumber": {
            "type": "long"
          }
        }
      }
    }
  }
}

我真的不能更改类型,有人知道我应该在查询中解决什么才能使我得到数值前缀的结果吗?

0 个答案:

没有答案