elasticsuite icon indicating copy to clipboard operation
elasticsuite copied to clipboard

allow exact match for strings

Open mvenghaus opened this issue 1 year ago • 4 comments

Sometimes you are in need to make an exact match instead of like in strings. For example I have a string with values "5", "50". With like I have no possibility to get only the value "5".

mvenghaus avatar Feb 06 '24 13:02 mvenghaus

Hi @mvenghaus

what's the output of this in the rule form ?

romainruaud avatar Feb 06 '24 15:02 romainruaud

german .. but i think you get it ;)

image

mvenghaus avatar Feb 06 '24 15:02 mvenghaus

Hello @mvenghaus,

Adding the operator is not enough though, one also needs to implement the specific query that must be generated to perform the "IS" operation which is to be intended as "contains this ... AND ONLY THIS". Otherwise, you will have the exact same "match" query generated by those lines.

The initial idea is probably to perform a "term" query. The issue is that "string" searchable-only attributes do not have an "untouched" subfield version (like option_text_color.untouched) of type "keyword" on which you can safely perform it. So you'll probably need to target the base field of a searchable-only text attribute (like "name") which is of type "text" but has the "keyword" analyzer.

It looks like a query like this works as expected :

{
  "size": 20,
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    },
    {
      "entity_id": {
        "order": "desc",
        "missing": "_first",
        "unmapped_type": "keyword"
      }
    }
  ],
  "from": 0,
  "query": {
      "term": {
          "name": "Joust Duffle Bag"
      }
  }
}

You would need to check that this approach works for all string/text attributes susceptible of appearing in the rules engine either because

  • they are searchable only
  • or they are filterable (we allow it, so meh...) only
  • or they are sortable only
  • or they have "use in promo rules" flag set to yes only
  • any combination of the above

Regards,

PS: As a side note, if you add "is", you should also probably add "is not" as a way to exclude a particular product in the context of a more complex rule. The negation should be taken care of automatically in the QueryBuilder on those lines.

rbayet avatar Mar 13 '24 07:03 rbayet

hey @rbayet ,

sorry for the late response!

I've created another pull request, because it combines another issue.

https://github.com/Smile-SA/elasticsuite/pull/3230

Regards Marcus

mvenghaus avatar Mar 25 '24 06:03 mvenghaus