"No Added Sugar" and "Added Sugar" term match

I'm looking for a way to tell elasticsearch that "no added sugar" and "added sugar" are separate phrases and should be indexed accordingly. I do not want them to conflate or conflict with each other.

Docs example:
"Cola No Added Sugar"
"Pepsi Added Sugar"

At the moment, when I search "added sugar", I get results that include "no added sugar". I've looked at various ways to acheive this including synomyms but I'm struggling.

How would I go about achieving this? Any advice is much appreciated.

1 Like

How do you search?
What is your index looking like?
Mapping?
More details, please.

Thank you for your reply. My mappings setup is pretty basic as follows:

  "mappings": {
    "properties": {
      "product_sku": {
        "type": "keyword"
      },
      "product_name": {
      	 "type": "text"
      }
    }
  }

I've indexed circa 10k products. With regards to search, I'm performing a "match" on the field "product_name" with a "minimum_should_match" of 50%.

The search works fine and most products show up quite accurately.

The issue is with 2-3 word phrases that elastic mismatches. For example:

  • "Added Sugar" should NOT show products with "No Added Sugar"
  • "Low Fat" should NOT show products with "Reduced Fat"

I hope the above helps give you a better idea what I'm trying to achieve.

Thanks

Alan

@Alan88 If you want to match your "product_name" as a keyword (exact match), then you must index it as "keyword" in your mapping and use Term query instead of Match query.

A match query behaves depending one the Analyzer/Tokenizer being in action. "Sugar" will match "Cola No Added Sugar" in your example.

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