查询字符串搜索不起作用

时间:2017-03-14 13:25:51

标签: elasticsearch

您好我正在使用未经过分析的字段

但是当我使用以下查询进行搜索时

 "query": {
    "query_string": {
      "query": "06H121605E",
      "default_field": "invoiceID"
    }
  }
}

我在结果中收到2份文件

但是当我去外卡时

它给我点击为空

 "query": {
    "query_string": {
      "query": "06H121605*",
      "default_field": "invoiceID"
    }
  }

以下是invoiceID字段的映射

 "invoiceID": {
                  "type": "string",
                  "index": "not_analyzed"
               },

查询:

GET ordersdetails/_search
{
 "size": 1000, 
 "query": {
   "query_string": {
     "query": "06H121605E\\*",
     "default_field": "invoiceID",
     "analyze_wildcard": true
   }
 }
}

输出

{
   "took": 5,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 0,
      "max_score": null,
      "hits": []
   }
}

1 个答案:

答案 0 :(得分:2)

对于版本5.2.1,您的查询可以使用:

{
    "query": {
        "query_string" : { 
            "query" : "06H121605*",
            "default_field": "invoiceID",
            "analyze_wildcard": true
        }
    }
}

以下是参考资料:

Documentation query string