【问题标题】:ElasticSearch bad regexElasticSearch 错误的正则表达式
【发布时间】:2023-03-13 07:34:01
【问题描述】:

我阅读了 ElasticSearch 的正则表达式查询文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html

没有提到如果将格式错误的正则表达式传递到查询中会发生什么。

所以我的问题是,如果正则表达式格式错误会怎样?是抛出异常,还是某种错误消息?

谢谢!

【问题讨论】:

  • 试试看,不是吗?
  • @ArchitSaxena 还没有访问 ES 实例的权限!

标签: regex elasticsearch lucene


【解决方案1】:

Elasticsearch 抛出异常。我添加了一个额外的[ 并使用 Kibana 中的开发工具控制台运行了正则表达式查询。

GET indexname/_search
{
    "query": {
        "regexp":{
            "field_name": "t.[st"
        }
    }
} 

我得到search_phase_exception如下:

{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: {\n  \"regexp\" : {\n    \"field_name\" : {\n      \"value\" : \"t.[st\",\n      \"flags_value\" : 65535,\n      \"max_determinized_states\" : 10000,\n      \"boost\" : 1.0\n    }\n  }\n}",
        "index_uuid": "6fy0LZRxQrOrNEFMGqL0wA",
        "index": "indexname"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "systems",
        "node": "LvCoGAkyTbiVIeyF7UtXTw",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: {\n  \"regexp\" : {\n    \"field_name\" : {\n      \"value\" : \"t.[st\",\n      \"flags_value\" : 65535,\n      \"max_determinized_states\" : 10000,\n      \"boost\" : 1.0\n    }\n  }\n}",
          "index_uuid": "6fy0LZRxQrOrNEFMGqL0wA",
          "index": "indexname",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "expected ']' at position 5"
          }
        }
      }
    ]
  },
  "status": 400
}

希望有帮助!

【讨论】:

  • 这不是一个无效的正则表达式,它是无效的 json。
  • 我已经编辑了答案,但有一个更具体的例外
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-19
  • 1970-01-01
相关资源
最近更新 更多