Unable to search text containing only special characters using elasticsearch query

Hi,

Here is my index with settings and mappings

curl -XPUT 'http://localhost:9200/special_index' -d '{
"settings": {
"numberOfShards": "5",
"numberOfReplicas": "1",
"analysis": {
"filter": {
"edge_ngram_filter": {
"type": "edge_ngram",
"min_gram": "1",
"max_gram": "100",
"token_chars": [
"letter"
]
},
"word_delimiter_for_phone": {
"type": "word_delimiter",
"catenate_all": true,
"generate_number_parts ": false,
"split_on_case_change": false,
"generate_word_parts": false,
"split_on_numerics": false,
"preserve_original": true
}
},
"analyzer": {
"edge_ngram_analyzer": {
"type": "custom",
"filter": [
"lowercase",
"edge_ngram_filter",
"word_delimiter_for_phone"
],
"tokenizer": "whitespace"
},
"case_insensitive_sort_analyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"documents": {
"properties": {
"id": {
"type": "string",
"index_analyzer": "edge_ngram_analyzer",
"search_analyzer": "standard",
"fields": {
"sort": {
"type": "string",
"analyzer": "case_insensitive_sort_analyzer"
}
}
},
"name": {
"type": "string",
"index_analyzer": "edge_ngram_analyzer",
"search_analyzer": "standard",
"fields": {
"sort": {
"type": "string",
"analyzer": "case_insensitive_sort_analyzer"
}
}
}
}
}
}
}'

Now inserted the below documents

curl -XPUT 'http://localhost:9200/special_index/documents/1' -d '{ "id": "101", "name": "abcd" }'
curl -XPUT 'http://localhost:9200/special_index/documents/2' -d '{ "id": "102", "name": "abc" }'
curl -XPUT 'http://localhost:9200/special_index/documents/3' -d '{ "id": "103", "name": "@#$%" }'
curl -XPUT 'http://localhost:9200/special_index/documents/4' -d '{ "id": "104", "name": "@#$%" }'
curl -XPUT 'http://localhost:9200/special_index/documents/5' -d '{ "id": "104", "name": "@#$%xyz" }'

When I search for name containing only alphabets and alphabets + special characters using elasticsearch query dsl it works.

curl -XGET 'http://localhost:9200/special_index/documents/_search?pretty' -d '{"query":{"query_string":{ "query": "name:@#$%xyz"}}}'

curl -XGET 'http://localhost:9200/special_index/documents/_search?pretty' -d '{"query":{"query_string":{ "query": "name:abcd"}}}'

But when I search for text containing only special characters it does not work. Kindly advise how to search for text containing only special characters.

curl -XGET 'http://localhost:9200/special_index/documents/_search?pretty' -d '{"query":{"query_string":{ "query": "name:@#$%"}}}'

Thanks in Advance,
Abhishek

I able to to fix the issue with some change in mappings and settings. Please find the details below.

curl -XPUT 'http://localhost:9200/special_chars_index' -d '{
"settings": {
"numberOfShards": "5",
"numberOfReplicas": "1",
"analysis": {
"filter": {
"edge_ngram_filter": {
"type": "edge_ngram",
"min_gram": "1",
"max_gram": "100",
"token_chars": [
"letter", "digit"
]
},
"word_delimiter_filter": {
"type": "word_delimiter",
"catenate_all": true,
"generate_number_parts ": false,
"split_on_case_change": false,
"generate_word_parts": false,
"split_on_numerics": false,
"preserve_original": true
}
},
"analyzer": {
"index_edge_ngram_analyzer": {
"type": "custom",
"filter": [
"lowercase",
"edge_ngram_filter"
],
"tokenizer": "whitespace"
},
"search_word_delimiter_analyzer": {
"type": "custom",
"filter": [
"lowercase",
"word_delimiter_filter"
],
"tokenizer": "whitespace"
},
"case_insensitive_sort_analyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"documents": {
"properties": {
"id": {
"type": "string",
"index_analyzer": "index_edge_ngram_analyzer",
"search_analyzer": "search_word_delimiter_analyzer",
"fields": {
"sort": {
"type": "string",
"analyzer": "case_insensitive_sort_analyzer"
}
}
},
"name": {
"type": "string",
"index_analyzer": "index_edge_ngram_analyzer",
"search_analyzer": "search_word_delimiter_analyzer",
"fields": {
"sort": {
"type": "string",
"analyzer": "case_insensitive_sort_analyzer"
}
}
},
"type": {
"type": "string",
"index": "not_analyzed",
"fields": {
"sort": {
"type": "string",
"analyzer": "case_insensitive_sort_analyzer"
}
}
}
}
}
}
}'

curl -XPUT 'http://localhost:9200/special_chars_index/documents/1' -d '{ "id": "101", "name": "abcd", "type": "pqrs" }'
curl -XPUT 'http://localhost:9200/special_chars_index/documents/2' -d '{ "id": "102", "name": "abc", "type": "pqr" }'
curl -XPUT 'http://localhost:9200/special_chars_index/documents/3' -d '{ "id": "103", "name": "@#$%", "type": "@#$%" }'
curl -XPUT 'http://localhost:9200/special_chars_index/documents/4' -d '{ "id": "@#$%", "name": "@#$%", "type": "@#$%" }'
curl -XPUT 'http://localhost:9200/special_chars_index/documents/5' -d '{ "id": "@#$%xyz", "name": "@#$%xyz", "type": "@#$%abc" }'
curl -XPUT 'http://localhost:9200/special_chars_index/documents/6' -d '{ "id": "abcd", "name": "()&^%$#@!+><;??//_==abcd", "type": "pqrs" }'
curl -XPUT 'http://localhost:9200/special_chars_index/documents/7' -d '{ "id": "abc", "name": "()&
^%$#@!+><;??//_==", "type": "pqr" }'

curl -XGET 'http://localhost:9200/special_chars_index/documents/_search?pretty' -d '{"query":{"query_string":{ "query": "name:\@\#\$\%"}}}'