venkat
venkat

Reputation: 33

White space query issue in elastic search

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 is not getting as single word match, it's querying as 3 words and getting more results.

Upvotes: 0

Views: 2250

Answers (1)

Kulasangar
Kulasangar

Reputation: 9434

In order for ES to ignore spaces, what if you have the plus signs between the string values in the below match:

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

OR

when you're creating the mapping for the fields, you can have the fields which you need to match exactly as below:

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
               }
           }
       }
   }
}'

Then of course you could go on match the string with white spaces.

Ref & this SO could be helpful.

Upvotes: 1

Related Questions