弹性搜索中的空白查询问题

时间:2016-11-30 09:21:47

标签: elasticsearch

GET taps/_search
{
  "query": {
    "bool": {
      "should": [
        { "match": { "test_card": "ZE-S-180x4" }},
        { "match": { "pf": "ZX480" }},
        { "match": { "fpc": "AEZE 3D MP+6E" }},
        { "match": { "rpd": "32" }},
        { "match": { "rel": "25" }},
        { "match": { "rel_type": "1234_daily" }}
      ]
    }
}
}

fpc没有获得单字匹配,它查询为3个单词并获得更多结果。

1 个答案:

答案 0 :(得分:1)

为了让ES忽略空格,如果下面的match中的字符串值之间有加号怎么办?

{ "match": { "fpc": "AEZE","3D","MP+6E" }}

当您为字段创建映射时,您可以将字段完全匹配,如下所示:

curl -XPUT localhost:9200/my_index -d '{
   "mappings": {
       "my_type": {
           "properties": {
               "instruments": {
                   "type": "string",
                   "index": "not_analyzed" <--- you need to have this for the field to get tokenized
               }
           }
       }
   }
}'

当然,你可以继续匹配白色空格的字符串。

Ref&amp;这个SO可能会有所帮助。