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);
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);```
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.