相关疑难解决方法(0)

ElasticSearch和Regex查询

我试图查询在"内容"字段的正文中具有日期的文档.

curl -XGET 'http://localhost:9200/index/_search' -d '{
    "query": {
        "regexp": {
            "content": "^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]((19|20)\\d\\d)$" 
            }
        }
    }'
Run Code Online (Sandbox Code Playgroud)

越来越近了吗?

curl -XGET 'http://localhost:9200/index/_search' -d '{
        "filtered": {
        "query": {
            "match_all": {}
        },
        "filter": {
            "regexp":{
                "content" : "^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]((19|20)\\d\\d)$"
                }
            }
        }
    }'
Run Code Online (Sandbox Code Playgroud)

我的正则表达式似乎已经关闭了.此正则表达式已在regex101.com上验证.以下查询仍然不返回我拥有的175k文档.

curl -XPOST 'http://localhost:9200/index/_search?pretty=true' -d '{
        "query": {
            "regexp":{
                "content" : "/[0-9]{4}-[0-9]{2}-[0-9]{2}|[0-9]{2}-[0-9]{2}-[0-9]{4}|[0-9]{2}/[0-9]{2}/[0-9]{4}|[0-9]{4}/[0-9]{2}/[0-9]{2}/g"
            }
        }
    }'
Run Code Online (Sandbox Code Playgroud)

我开始认为我的索引可能没有为这样的查询设置.您必须使用哪种类型的字段才能使用正则表达式?

mappings: {
    doc: {
        properties: {
            content: {
                type: string
            }title: {
                type: string
            }host: {
                type: string
            }cache: {
                type: string …
Run Code Online (Sandbox Code Playgroud)

regex elasticsearch

11
推荐指数
1
解决办法
3万
查看次数

标签 统计

elasticsearch ×1

regex ×1