Unable to escape special character using Java REST API

Hi,

I'm using query_string which is Lucene-based, and when I'm trying to send a query with "role" field contains the string "INFRA-Server", it cannot find any results because of the "-" sign.
I tried to escape it, but it doesn't work..

"role" field is of type "text", can anyone please help me solve this issue?

 queryString = "( hostname:\"OR\" AND role:*INFRA-Server*) AND MachineTime:[1674746651 TO 1675265051]"

QueryBuilder query = QueryBuilders
            .queryStringQuery(queryString);

Hi @Avi_Buk

you tried to run like this: role:INFRA-Server ?

If I had a sample document I can try to simulate it too.

Hi, thank you,

I would like to perform a "contain" query, means, looking for all the documents contains the role "INFRA-Server", example of a single document :

{
            "role": "INFRA-Server.zse",
            "hostname": "OR",
            "region": "EMEA",
            "ipaddr": "10.25.83.12"
}

I tried:

POST idx_test/_doc
{
  "role": "INFRA-Server.zse",
  "hostname": "OR",
  "region": "EMEA",
  "ipaddr": "10.25.83.12"
}


POST idx_test/_doc
{
  "role": "INFRA-Server.tre",
  "hostname": "OR",
  "region": "EMEA",
  "ipaddr": "10.25.83.12"
}

GET idx_test/_search
{
  "query": {
    "query_string": {
      "query": "(hostname:\"OR\" AND role:INFRA-Server)"
    }
  }
}

Java Code

    var queryString = QueryStringQuery.of(qs -> qs.query("(hostname:\"OR\" AND role:INFRA-Server)"));
    var searchRequest = SearchRequest.of(sr -> sr.query(queryString._toQuery()).index("idx_test"));

    var response = client.search(searchRequest, sClass.class);```

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