Query with regular expression special characters

HI everyone!
I have a lot of fields with XML text and i want to make a query to check if some tags are closed.
In order to do that i'm using the whitespace analyzer (so that i can query for char like "<").

Assuming that i have a field like this one
"example": "<attribute>hi</attribute>"

i tried to query for :

GET myindex/_search
{
    "query": {
        "regexp": {
            "example": { 
                "value": "</attribute>",
                "flags" : "NONE",
                "max_determinized_states": 10000,
                "rewrite": "constant_score"
            }
        }
    }
}

And i get no hits for it.
I tried to query for attribute and i get the hit...
I tried to query for "<" char like this:

GET prova/_search
{
    "query": {
        "regexp": {
            "ved": { 
                "value": "'<'",
                "flags" : "NONE",
                "max_determinized_states": 10000,
                "rewrite": "constant_score"
            }
        }
    }
}

i get no hits... i know i'm probably doing something wrong but i can't understand what..
can someone give me an advice?

my assumption here (that could be validated if this was a reproducible example including the index creation and document indexing), is that your field is analyzed and thus does not contain the term '' anymore. You could try using the keyword field

PUT myindex/_doc/1
{
  "example" : "<attribute>hi</attribute>"
}

GET myindex/_mapping

GET myindex/_search
{
  "query": {
    "regexp": {
      "example.keyword": {
        "value": ".*\\</attribute\\>"
      }
    }
  }
}

Note that I would always try to refrain from regexp queries, so maybe adding some more context to get rid of it might be another idea.

Thank you very very very much!!!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.