I suspect the analyzer on your fields is standard or similar. This means chars like : and - were stripped:
GET _analyze
{
"text": "John-Doe",
"analyzer": "standard"
}
showing
{
"tokens" : [
{
"token" : "john",
"start_offset" : 0,
"end_offset" : 4,
"type" : "<ALPHANUM>",
"position" : 0
},
{
"token" : "doe",
"start_offset" : 5,
"end_offset" : 8,
"type" : "<ALPHANUM>",
"position" : 1
}
]
}
Let's create our own analyzer which is going to keep the special chars but lowercase them all other chars the same time:
PUT multisearch
{
"settings": {
"analysis": {
"analyzer": {
"with_special_chars": {
"tokenizer": "whitespace",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"properties": {
"firstName": {
"type": "text",
"fields": {
"with_special_chars": {
"type": "text",
"analyzer": "with_special_chars"
}
}
},
"ip": {
"type": "ip",
"fields": {
"with_special_chars": {
"type": "text",
"analyzer": "with_special_chars"
}
}
}
}
}
}
Ingesting 2 sample docs:
POST multisearch/_doc
{
"ip": "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
}
POST multisearch/_doc
{
"firstName": "John-Doe"
}
and applying your query from above:
GET multisearch/_search
{
"query": {
"query_string": {
"fields": [
"id",
"email",
"firstName.with_special_chars",
"lastName",
"phone",
"ip.with_special_chars"
],
"query": "2001\\:0db8* OR john-*"
}
}
}
both hits are returned.
Two remarks: 1) note that we were searching .with_special_chars instead of the main fields and 2) I've removed the leading wildcard from the ip -- those are highly inefficient.
Final tips since you asked for optimization suggestions: the query could be rewritten as
GET multisearch/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"id": "tegO63EBG_KW3EFnvQF8"
}
},
{
"match": {
"email": "[email protected]"
}
},
{
"match_phrase_prefix": {
"firstName.with_special_chars": "john-d"
}
},
{
"match_phrase_prefix": {
"firstName.with_special_chars": "john-d"
}
},
{
"match": {
"phone.with_special_chars": "+151351"
}
},
{
"wildcard": {
"ip.with_special_chars": {
"value": "2001\\:0db8*"
}
}
}
]
}
}
}
- Partial
id matching is probably an overkill -- either the term catches it or not
email can be simply matched
first- & lastName: I suspect match_phrase_prefix is more performant than wildcard or regexp so I'd go with that (as long as you don't need the leading *)
phone can be matched but do make sure special chars can be matched too (if you use the int'l format)
- use
wildcard for the ip -- same syntax as in the query string
Try the above and see if you notice any speed improvements!