My search term is "A & H" and I want to find any item that has that term somewhere in either
Number or
VendorName - and it has to be exact. I don't want it if it has an A and a space, an H somewhere, or a
& without the full search string. (There are a few other restrictions like Customer, you'll see that in my code)
I keep getting way too many results that do not have the entire search string in there. Can someone tell me how to phrase the query correctly, and/or what the Java would look like to put that together?
What I have tried:
{
"from" : 0,
"size" : 500,
"query" : {
"bool" : {
"must" : [ {
"bool" : {
"must" : {
"match" : {
"CustomerID" : {
"query" : 5,
"type" : "boolean"
}
}
}
}
}, {
"multi_match" : {
"query" : "A & H",
"fields" : [ "VendorName", "Number" ]
}
} ]
}
},
"sort" : [ {
"VendorName.raw" : {
"order" : "asc"
}
} ]
}
- which I built by doing:
MultiMatchQueryBuilder mqbs = QueryBuilders.multiMatchQuery(criteriaQuery, "VendorName", "Number");
vendorQuery.must(mqbs);
SearchSourceBuilder searchBuilder = buildBaseSearchSourceBuilder(mapPayload).query(vendorQuery);
searchBuilder.sort("VendorName.raw", SortOrder.ASC);
Search search = new Search.Builder(searchBuilder.toString()).addIndex(searchProperties.getVendorAliasName())
.addType(VENDOR_TYPE).build();
SearchResult result = client.execute(search);