2

Is it possible to make phrase searches for multi-word synonyms in Elasticsearch?

Let's say I have this synonym:

strip steak bacon, ssb, strip-steak bacon

And this text in a document:

Kevin burgdoggen turkey, spare ribs pancetta pastrami drumstick strip steak bacon beef ribs pork. 
Jowl sirloin tenderloin hamburger alcatra short loin biltong cow doner ribeye tri-tip sausage bacon 
capicola pork. Filet mignon meatloaf shoulder cupim tongue meatball. Shankle cow strip steak tail pig
buffalo pork picanha cupim porchetta kielbasa beef. Ground round pork loin filet mignon turducken.
Beef pancetta buffalo strip steak, ground round salami flank porchetta hamburger chicken turducken 
venison sirloin pastrami.

I query the index for ssb plain and simple:

"query": {
    "match": {
      "body": "all the ssb are belong to us"
    }
}

Then I want it to be interpreted as:

all the "strip steak bacon" are belong to us

Otherwise I will get the results and highlights based on all words (all, the, strip, steak, bacon, are, belong, to, us).

Is this even possible to do? I have tried to find docs on this, but they all go the other way using directional synonyms (strip steak bacon => ssb). Now I am seriously considering adding it to my application logic instead of doing it in Elasticsearch, and replacing ssb's in the query manually which feels like a really bad idea.

Tubbe
  • 1,068
  • 6
  • 22
  • I think that Synonyms are what you need, but you'll have to reindex https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html – Jaycreation Nov 05 '20 at 08:54
  • @Jaycreation Synonyms are what I already use. This looks more like a related solution, but I can't really get it to work with my other filters: https://www.jocas.lt/blog/post/synonym-graph-phrase-search/ – Tubbe Nov 06 '20 at 11:09

0 Answers0