In the official Elasticsearch documentation中写着Any reserved character can be escaped with a backslash "\*" including a literal backslash character: "\\"
。
您能解释一下为什么这样查询吗
{
"query": {
"bool": {
"must": [
{
"regexp": {
"path": ".*test\/test.txt.*"
}
},
{
"match": {
"user_id": 1
}
}
]
}
}
}
找不到这样的索引
{
"_index": "pictures",
"_type": "picture",
"_id": "wiskQ2kBi923Omj4U",
"_score": 1,
"_source": {
"user_id": 1,
"tag": [],
"text": "some text",
"path": "test/test.txt"
}
}
答案 0 :(得分:1)
自path
被分析字段以来,正则表达式将不匹配它。原因是test/test.txt
被标记为两个不同的术语:test
和test.txt
。由于path
有一个数据类型为keyword
的子字段 keyword
,它将直接为test/test.txt
编制索引,因此您应该在该字段上进行查询,即path.keyword
。
使用以下查询:
{
"query": {
"bool": {
"must": [
{
"regexp": {
"path.keyword": ".*test/test.txt.*"
}
},
{
"match": {
"user_id": 1
}
}
]
}
}
}