Multi field search criteria results to include all input or either words

Currently using Elastic Search for inventory search feature implementation and trying to build query logic.

Search requirements:

  1. User shall be able to search for words in ProductName, BrandName and description fields
    • Match query is used to search on ProductName fields
    • Multi_Match query is used to search any input words in BrandName and Description fields
  2. System to return search results including user input all words or either words (Input search words are separated using space)
    • Wildcard quey is used to search all the words in Description
    • Multiple bool with must and should is used to search all or either words to fetch results

Logic: MUST (Wildcard Word1 AND Word2 on Field:description) OR (SHOULD (Match "Word1 Word2" on Field:productName) OR (multi_match Word1 Boost 2.0 on Fields:["description","brandName"]) OR (Match Word2 on Fields:["description","brandName"]))

Inventory Index Mappings reference:
{"inventory":{"mappings":{"_routing":{"required":true},"properties":{"productName":{"type":"text","fields":{"keyword":{"type":"keyword","normalizer":"lowercase"}}},"brandName":{"type":"text","fields":{"keyword":{"type":"keyword","normalizer":"lowercase"}}},"description":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}}}

Search query for user input "Dove 3.75 oz":
POST inventory/_search{"from":0,"query":{"bool":{"must":[{"bool":{"should":[{"match":{"productName":{"operator":"and","query":"dove 3.75 oz"}}},{"multi_match":{"fields":["description","brandName"],"query":"dove","boost":2.0}},{"multi_match":{"fields":["description","allBrandNames"],"query":"3.75"}},{"multi_match":{"fields":["description","allBrandNames"],"query":"oz"}},{"bool":{"must":[{"wildcard":{"description":{"value":"*dove"}}},{"wildcard":{"description":{"value":"*3.75"}}},{"wildcard":{"description":{"value":"*oz*"}}}]}}]}}]}},"size":20,"sort":[{"_score":{"order":"desc"}}]}

Question: Is above compound query good approach or any different query options available?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.