Elasticsearch query issue with reserved characters

Hi all,
I have indexed two documents

  1. {"title": "+" }
  2. {"title": "a + b" }
    By using query string query , I have search queries for the above two documents in different manner.
    Also, I have not changed any analyzers. Default analyzer has been used.
  1. {
    "query": {
    "query_string" : {
    "default_field" : "title",
    "query" : "+"
    }
    }
    }
    the above query gives a parsing exception which is legit.

2.{
"query": {
"query_string" : {
"default_field" : "title",
"query" : "\+"
}
}
}
this query outputs:

"hits": [
{
"_index": "my_index1",
"_type": "my_item",
"_id": "005",
"_score": 0.9808292,
"_source": {
"title": "+"
}
}
]
the above output also seems legit.

  1. {
    "query": {
    "query_string" : {
    "default_field" : "title",
    "query" : " + "
    }
    }
    }
    in the above query space exists before and after "+" character , this outputs:
    "hits": [
    {
    "_index": "my_index1",
    "_type": "my_item",
    "_id": "005",
    "_score": 1.2039728,
    "_source": {
    "title": "+"
    }
    }
    ]
    My issue is why parsing exception is not thrown here and why escaping "+" is not necessary here"? If Elasticsearch is finding a way to parse "+"in some manner, why is "a + b" not in the hits?

4.{
"query": {
"query_string" : {
"default_field" : "title",
"query" : "a + b"
}
}
}
this query outputs:
"hits": [
{
"_index": "my_index1",
"_type": "my_item",
"_id": "005",
"_score": 0.9808292,
"_source": {
"title": "+"
}
}
]
I don't understand how my query is parsing "+" and not throwing an exception. If Elasticsearch is finding a way to parse "+"in some manner, why is "a + b" not in the hits?

  1. {
    "query": {
    "query_string" : {
    "default_field" : "title",
    "query" : "a \+ b"
    }
    }
    }
    output to this query :
    "max_score": 0.6931472,
    "hits": [
    {
    "_index": "my_index1",
    "_type": "my_item",
    "_id": "007",
    "_score": 0.6931472,
    "_source": {
    "title": "a + b"
    }
    }
    ]

if the query is using default analyzers (since I have not used any analyzers) how is "+" not in the hits here?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.