Get documents whose text field contains only a number value in Elasticsearch

Does there exist any query or filter that gives me only the documents where specific text field contains only a number value?

I have a text field (called "guess", feel free to use another name) that contain only one number in most cases ("guess":"333" for example, and not "guess":"34 34") or free text ("guess":"blah blah blah" for example, and "guess":"34 34" is free text too).

Best Regards!

Upvotes: 0

Views: 3238

Answers (1)

Peter Dixon-Moses
Peter Dixon-Moses

Reputation: 3209

Use a Regexp Filter (or Query)

{
    "query": {
        "filtered": {
            "query": {
                "match_all": {}
            },
            "filter": {
                "regexp":{
                    "guess": "[0-9]*"
                }
            }
        }
    }
}

If you need to match more complex number formats, reference this post

Upvotes: 3

Related Questions