I'm facing some problems in the wildcard query search.
My purpose is that if I search for word1 word2 word3, I'll find all the results that can have prefixes and suffixes before and after each word that compose the entire string.
The structure of my index is:
{
"my_index": {
"aliases": {},
"mappings": {
"properties": {
"attributes": {
"properties": {
"name": {
"properties": {
"value": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
}
}
}
},
"settings": {
...
}
}
}
So I have a field attributes.name(text) where I want to match values.
My index contains objects where attributes.name values are:
word1,word1suffix,word1 word2,word1 word2suffixword1 word2 word3.
Before running the search, I internally add wildcards before and after each word:
word1 word2 word3 => *word1* *word2* *word3*
Then I run this query:
{
"size": 10,
"index": "my_index",
"body": {
"query": {
"bool": {
"should": [
{
"wildcard": {
"attributes.name.value": {
"value": "*word1* *word2* *word3*",
"rewrite": "constant_score"
}
}
}
],
"must": [],
"minimum_should_match": 1
}
}
},
"explain": false
}
The strange thing I'm facing is that, even if in the index I have exactly an object called word1 word2 word3, I cannot find it through this kind of wildcard search (I know that in that case, it's better a match_phrase or term query, but it's just to understand why this simple case is not working).
If I try with less words like:
*word1*, I find bothword1,word1suffix,word1 word2andword1 word2suffix*word1* *word2*, I find bothword1 word2andword1 word2suffix*word1* *word2* *word3*, none
So it seems that this strange behavior starts when I search for results with too many words.
Just for debug, my values are stored in the index in this way:
{
"attributes": {
"name": [{
"value": "word1 word2 word3"
}],
}
}
Last consideration: I managed to find that word1 word2 word3 by searching in the field attributes.name.value.keyword (I think .keyword is automatically generated in the index on every textual fields) rather than attributes.name.value. The problem is that if I use .keyword the analyzer doesn't work, so I think it's not a good solution.