0
votes

word search in elasticsearch is working fine, but it seems to neglect all special characters. For example, i have this data (123) apple and 123 pear, but when i query "(123)", i expect "(123) apple" to be the first that appear instead of "123 pear". I have tried to change tokeniser from standard tokenizer to whitespace tokenizer, but still not working. Kindly advice. Thanks!

Data: 
(123) apple
 123 pear

Query: "(123)"

Expected:
(123) apple
 123 pear

Actual result:
 123 pear
(123) apple

1

1 Answers

0
votes

I tried with whitespace tokenizer, it worked

PUT /index25
{
  "mappings": {
    "properties": {
      "message":{
        "type": "text",
        "analyzer": "my_analyzer"
      }
    }
  }, 
   "settings": {
      "analysis": {
         "analyzer": {
            "my_analyzer": {
               "type": "custom",
               "filter": [
                  "lowercase"
               ],
               "tokenizer": "whitespace"
            }
         }
      }
   }
}

Data:

 [
      {
        "_index" : "index25",
        "_type" : "_doc",
        "_id" : "cIC70m0BD5PlkoxX1O0B",
        "_score" : 1.0,
        "_source" : {
          "message" : "123 pear"
        }
      },
      {
        "_index" : "index25",
        "_type" : "_doc",
        "_id" : "cYC70m0BD5PlkoxX9-3n",
        "_score" : 1.0,
        "_source" : {
          "message" : "(123) apple"
        }
      }
    ]

Query:

GET index25/_search
{
  "query": {
    "match": {
      "message": "(123)"
    }
  }
}

Response:

 [
      {
        "_index" : "index25",
        "_type" : "_doc",
        "_id" : "cYC70m0BD5PlkoxX9-3n",
        "_score" : 0.47000363,
        "_source" : {
          "message" : "(123) apple"
        }
      }
]

Query:

GET index25/_search
{
  "query": {
    "match": {
      "message": "123"
    }
  }
}

Response:

 [
      {
        "_index" : "index25",
        "_type" : "_doc",
        "_id" : "cIC70m0BD5PlkoxX1O0B",
        "_score" : 0.9808292,
        "_source" : {
          "message" : "123 pear"
        }
      }
    ]