0

I want find all items filtered by ID match some regular expression like

*TEST123*   //pattern for regexp

So expected result are items

ATEST123001

ATEST123002

ATEST123003

TTTTEST123001

...

I can create some script which scan full storage and save IDs in log-file which can check later. But I want to find some better solution

Updated I tried

"query" : { "match_all" : { }, "filtered" : { "filter" : { "regexp": { "id":".test123." } } } }, }

I receive

//nested: ElasticsearchParseException[Expected field name but got START_OBJECT \"filtered\"]

When I tried

{
  "regexp": {
    "id": "test123"
  }

}

//Parse Failure [No parser for element [regexp]]]

ES 1.7.4 and Lucene 4.10.4

2 Answers 2

1

You can use regular expression queries. The regexp query allows you to use regular expression term queries.

Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html

Sample regex query :

{
    "regexp":{
        "id": "*test123*"
    }
}

Update: In 2.0 regexp filter has been replaced by regexp query.

   {
      "query": {
        "filtered": {
          "filter": {
            "regexp":{
              "id":".*TEST123.*"
            }
          }
        }
      }
    }
Sign up to request clarification or add additional context in comments.

5 Comments

I have tested this type of example but I receive Parse Failure [No parser for element [regexp]]]; }]", I'm using ES 1.7.4 and Lucene 4.10.4
ES 1.7.4 and Lucene 4.10.4
Updated the answer for your version. If still not working, update your question with what you have tried.
I removed comma before running request. I'm testing at Marvel/Sense - it is autoformat before running. So it is not correct answer
I have tried it locally and it is working perfectly fine. Your regex is also wrong. it should be ".*TEST123.*"
0

You can try Query String.

{
"query": {
 "query_string": {
    "default_field": "if",
    "query": "*test123*"
   }
  }
}  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.