gpt4 book ai didi

regex - 在Elasticsearch中使用正则表达式在匹配查询中斜杠不起作用

转载 作者:行者123 更新时间:2023-12-02 22:55:58 25 4
gpt4 key购买 nike

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"
}
}

最佳答案

由于path是分析字段,因此正则表达式将不匹配它。原因是test/test.txt被标记为两个不同的术语:testtest.txt。由于path具有数据类型keyword的子字段 keyword ,它将按原样索引test/test.txt,因此您应该在此字段上查询path.keyword

使用以下查询:

{
"query": {
"bool": {
"must": [
{
"regexp": {
"path.keyword": ".*test/test.txt.*"
}
},
{
"match": {
"user_id": 1
}
}
]
}
}
}

关于regex - 在Elasticsearch中使用正则表达式在匹配查询中斜杠不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54968057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com