Reputation: 17
In OpenSearch, there are documents that contain the following field:
"address": {
"city": "London",
"street": "Baker street",
"building": "221b",
"floor": "1",
"room": "4"
}
When I send a request with request body through the API like this:
{
"filters": {
"address": "london baker street 221bsdfsdf"
}
}
We receive all documents containing "london baker street 221b". How can I make it so that a request of this kind does not return documents, since "london baker street 221bsdfsdf" is an invalid address? Here is a block of code from the API:
if (requestFilters.address() != null) {
boolQueryBuilder.must(
new Query.Builder().nested(
new NestedQuery.Builder()
.path("address")
.query(
queryForMatchField(
List.of(
"address.city",
"address.street",
"address.building",
"address.room"),
requestFilters.address()
)
)
.build()
).build()
);
private Query queryForMatchField(List<String> fieldNames, String value) {
return new Query.Builder().multiMatch(
new MultiMatchQuery.Builder()
.fields(fieldNames)
.query(value)
.fuzziness("AUTO")
.zeroTermsQuery(ZeroTermsQuery.All)
.build()
).build();
}
Upvotes: 0
Views: 54
Reputation: 1543
may be Minimum_should_match could help
or you can use keyword mapping with exact match
Upvotes: 1