Reputation: 634
In the official Elasticsearch documentation there is written Any reserved character can be escaped with a backslash "\*" including a literal backslash character: "\\"
.
Can you explain me why query like this
{
"query": {
"bool": {
"must": [
{
"regexp": {
"path": ".*test\/test.txt.*"
}
},
{
"match": {
"user_id": 1
}
}
]
}
}
}
doesn't find index like this
{
"_index": "pictures",
"_type": "picture",
"_id": "wiskQ2kBi923Omj4U",
"_score": 1,
"_source": {
"user_id": 1,
"tag": [],
"text": "some text",
"path": "test/test.txt"
}
}
Upvotes: 2
Views: 3097
Reputation: 7864
Since path
is analysed field the regex wont match it. The reason is that test/test.txt
get tokenised into two different terms: test
and test.txt
. Since path
has a sub-field keyword
of data type keyword
which will index test/test.txt
as it is, you should query on this field i.e. path.keyword
.
Use the below query:
{
"query": {
"bool": {
"must": [
{
"regexp": {
"path.keyword": ".*test/test.txt.*"
}
},
{
"match": {
"user_id": 1
}
}
]
}
}
}
Upvotes: 7