Elasticsearch PHP Client implementation for a webshop

Hello there,

I am using the Elasticsearch PHP client (8.3), as can be found on: github

I've used several types of queries to find and filter through results on several indices to find relevant/popular. Some more complex than other but all nonetheless didn't give the hoped results we wanted to achieve.

I'm using Elasticsearch to search through data for a web shop. So features like handling typos and sorting by relevancy/popularity is quite important. An example of some of the queries I've tried is as follows:

"index" => "search-index"
  "body" => [
    "query" => [
      "bool" => [
        "should" => [
          0 => [
            "match" => [
              "title" => [
                "query" => "audi a22"
                "fuzziness" => "2"
                "minimum_should_match" => "1"
              ]
            ]
          ]
          1 => [
            "match" => [
              "typeId" => [
                "query" => 5431
                "boost" => 1.6
              ]
            ]
          ]
        ]
        "must" => [
          "term" => [
            "active" => 1
          ]
        ]
      ]
    ]
    "sort" => [
      "_score" => [
        "order" => "desc"
      ]
      "siteScore" => [
        "order" => "desc"
      ]
    ]
    "fields" => [
      0 => "title"
      1 => "productId"
    ]
    "_source" => false
    "size" => 300
  ]
]

In this example we want to look for a specific product by searching throughout the titles, boosting the ones that correspond to a given type and sort the result based on the relevancy and popularity (this last one is tracked on another platform). It doesn't achieve this though, it matches products like "m22" or "s22" better than "a22". Also sorting on several fields like this does not create the desired effect. It would be better to match products better and then sort on popularity, how could this be done though?

My question to you is as follows: is there a better way to achieve the requirements as specified above?

I feel like the queries I'm writing might be getting too complicated when they don't really need to be. Any help would be appreciated.

My thanks in advance.

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