2

My question is simple, I can't use @ in the search query. Finally, I found that I can escape the special characters using the backslash.

GET index/_search
{
  "size": 20,
  "query": {
    "query_string": {
      "query": "\@as",
      "analyzer": "keyword"
    }
  }
}

But when I try to do that I got the following error Unrecognized character escape '@' (code 64)\n at. And when I try without @ symbol i got the results without @ symbol like

  1. As missed as ever
  2. As. GUI
  3. As if And so on. can any one suggest how can I achieve the previous query can be executed as per my expectation?

I am using

  • Elasticsearch 2.4.1
  • Ubuntu 14.04
  • Kibana 4.6.1
Tamizharasan
  • 293
  • 1
  • 5
  • 18

1 Answers1

0

You get the error because there is no need to escape the '@' character.
"query": "@as" should work.
You should check your mappings as well, if your fields are not marked as not_analyzed(or don't have keyword analyzer) you won't see any search results - standard analyzer removes characters like '@' when indexing a document.
UPDATE
query_string uses _all field by default, so you have to configure this field in the way similar to this example:

PUT index 
{
   "mappings":{
      "book":{
         "_all":{
            "type":"string",
            "index":"analyzed",
            "analyzer":"whitespace"
         },
         "properties":{
            "name":{
               "type":"string",
               "index":"not_analyzed"
            }
         }
      }
   }
}

PUT /index/book/1
{
"name" : "@foo bar"
}

GET index/_search
{
  "size": 20,
  "query": {
    "query_string": {
      "query": "@foo",
      "analyzer": "keyword"
    }
  }
}
Taras Kohut
  • 2,505
  • 3
  • 18
  • 42
  • I didn't create any mapping at all. I just store the values as it is. And I can see in kibana that the field is indexed and analyzed. So if it uses the standard analyzer and removes the character what should I do now to get my results. – Tamizharasan Oct 16 '16 at 15:28
  • if you need to have a possibility to search by special characters you need to change your mappings – Taras Kohut Oct 16 '16 at 16:22
  • what type of mapping is matched to my scenario? I am new to the es, So please elaborate the answer. – Tamizharasan Oct 16 '16 at 16:51
  • I am storing a million records per day. can you suggest me how to structure my index like many index or single index? Is there any problem will occur when I use a single index of for all of my data. what is the best practice? – Tamizharasan Oct 18 '16 at 05:48
  • I think it's not a good idea to blindly chose some approach without knowing how ES works. You can start with reading this chapter: https://www.elastic.co/guide/en/elasticsearch/guide/current/scale.html – Taras Kohut Oct 18 '16 at 09:51