gpt4 book ai didi

ElasticSearch:如何在索引上应用正则表达式

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

我试图将搜索查询的返回限制为仅以 abc-* 模式开头的索引。

我尝试了以下正则表达式,但没有用。

{  
"sort": [
{
"timestamp": {
"order": "desc",
"unmapped_type": "boolean"
}
}
],
"query": {
"filtered": {
"query": {
"query_string": {
"regexp": {
"index": "abc-*"
}
}
},
"filter": {
"bool": {
"must": [
{
"range": {
"timestamp": {
"gte": "now-24h"
}
}
}
]
}
}
}
}
}

是否可以使用索引查询并在其上应用正则表达式?即使是以下内容也无法正确过滤:

{

"sort": [
{
"timestamp": {
"order": "desc",
"unmapped_type": "boolean"
}
}
],
"query": {
"filtered": {
"query": {
"indices" : {
"query" : { "regexp" : { "index" : "abc-.*" } }
}
},
"filter": {
"bool": {
"must": [
{
"range": {
"timestamp": {
"gte": "now-24h"
}
}
}
]
}
}
}
}

}

最佳答案

只需指定您的 index pattern in the URL directly 即可获得更简单的解决方案:

POST /abc-*/_search
{
"sort": [
{
"timestamp": {
"order": "desc",
"unmapped_type": "boolean"
}
}
],
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"range": {
"timestamp": {
"gte": "now-24h"
}
}
}
]
}
}
}
}
}

关于ElasticSearch:如何在索引上应用正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43653036/

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