Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
Posted
Updated 12-Jun-18 17:05pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900