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

har*_*ant 4 elasticsearch

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

我尝试了以下正则表达式,但它不起作用。

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

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

{

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

}
Run Code Online (Sandbox Code Playgroud)

Val*_*Val 5

有一个更简单的解决方案,只需直接在 URL 中指定索引模式即可:

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