Im working with in Java, quarkus and elasticsearch, using quarkus-elasticsearch-rest-high-level-client and I have the following question for a search query:
It is possible to do a MultiMatchQuery with regEx? beacuse in my data I have two fields: "numberId1" and "numberId2", and in the search criteria I have a parameter that could match the last four digits of one of those fields, and I need to find a way to do that.
Example: If my data is this:
[
{...,
numberId1: 45678,
numberId2:78523,
...,},
{...,
numberId1: 11111,
numberId2:105678,
...,},
{...,
numberId1: 22222,
numberId2:785823,
...,}
]
and if my shearch parameter is "5678" I have to return this ones:
[
{...,
numberId1: 45678, (matches with numberId1)
numberId2:78523,
...,},
{...,
numberId1: 11111,
numberId2:105678,(matches with numberId12)
...,}
]
I was trying to do something like this to generate the search query but it doesnt work:
listRegEx.add(QueryBuilders.regexpQuery("numberId1",".*"+searchParameter));
listRegEx.add(QueryBuilders.regexpQuery("numberId2",".*"+searchParameter));
for(RegexpQueryBuilder a:listRegEx){
query.must(a);
}
I need something like multimatch with regex but I couldnt find out how to make it work
Something like this:
MultiMatchQueryBuilder mmqb=QueryBuilders.multiMatchQuery(".*"+searchParameter,
"numberId1",
"numberId2");
mmqb.type(MultiMatchQueryBuilder.Type.CROSS_FIELDS);
mmqb.operator(Operator.AND);
listMulti.add(mmqb);