Advanced Search Queries in Elastic App Search (Example) | Elastic Blog
Engineering

Advanced Search Queries in Elastic App Search

Elastic App Search is a solution built on top of Elasticsearch that offers a curated experience for search use cases right out of the box. It makes it much easier and faster to build common search features like autocomplete, faceting, and tune-able relevance. App Search provides this through a more concise API and an intuitive admin dashboard UI that’s accessible for both developers and non-developers alike.

App Search may expose fewer APIs than Elasticsearch, but don’t let that mislead you into thinking that App Search only supports the more basic features of search. The truth is, Elastic App Search can be used to support search use cases with more complex data models and relevance scoring requirements. This blog post highlights two of those features: Result Grouping and Boosting.

Result Grouping

Result grouping is a query feature that groups or “rolls up” results by a higher level entity. For example, within an ecommerce search implementation, each document in the search engine may represent a unique product variant at the SKU level. One document will represent a shoe with Style ID 123, size 6, colour blue and another might represent represent Style ID 123, size 7, colour green.

[
  {
    style_id: 123
    size: 6,
    colour: blue
  },
  {
    style_id: 123,
    size: 7,
    colour: green
  }
]

This SKU-based data model allows the user to drill down by SKU level attributes such as size and colour accurately. But when you return results on this SKU, you will overwhelm users with separate search result for each variant.

In practicality, consider an online store’s search experience when a user queries for “sneakers”. Within the first 8 results, there is one shoe in 6 different colours and a second shoe in 2 colours. This is not helpful — there are really only 2 different types of shoe, yet we have 8 results!

A much more helpful search experience would return 8 unique products. Each product variant would then be grouped together to provide a cleaner user experience. The user would see, at a glance, the colours, sizes, and so on, available for each individual product.

Applying a Result Grouped query is as simple as adding a parameter to specify the group key field alongside the other query parameters:

{
  "query": "sneakers",
  "group": {
    "field": "style_id"
  }
}

Value Boosting and Functional Boosting

A common requirement is to have certain document types boosted in the results list. You might want restaurants who accept reservations to score higher than those that do not. Or, you may want to find a national park that is also a world heritage site, or a shoe that comes in velcro straps instead of laces.

You can accomplish this through Value Boosting. The following configuration states that documents where ‘accepts_reservations’ = ‘true’ should be boosted with an Impact of 2. The higher the Impact, the higher the score when the value is present:

relevance-tuning-value.png

Elastic App Search also allows you to define Weights on a field. One may want the name or title field to be the more important field, compared to something like the body text or the URL. Similar to Boosts, Weights can be scaled with an Impact from 1-10. But Boosts are different from Weights in that they don’t have anything to do with how well the user’s query matches the document. Boosting is about influencing the score based on a field value within the document.

While the Value Boost influences the score based on a static value, Functional Boosts allow you to influence the score using a numeric field value on the document. In the next image, we’re boosting documents based on the value of the Rating field to help make sure highly rated restaurants show up closer to the top of the results:

relevance-tuning-logarithmic.png

App Search provides detailed control over Functional Boosts allowing you to select a Logarithmic, Exponential, or Linear function and a Multiple or Add operation. These different Boosting functions offer fine-tuned control over how a numeric field such as Number of Clicks, Number of Likes, and Gross Margin, should influence the scoring.

Finally, App Search offers a Proximity Boosting feature that allows you to influence scoring based on the difference between a given value and the document’s field value. App Search has four field types: text, number, date, and geolocation. Proximity Boosting works on number, date, and geolocation fields.

If we want restaurant result scores to gradually diminish as the distance increases between a restaurant and the user’s current location, we could configure a Proximity Boost that looks like this:

relevance-tuning-geo.png

The Proximity Boost supports three different functions: Gaussian, Linear, or Exponential. A nice bonus is that these complex boosting features are configurable within the Admin Dashboard! And we have helpful documentation to guide you through it. This means that even non-developers can tune these features without needing to alter the application code.

Summary

Elastic App Search is a search solution that exposes powerful Elasticsearch features like Result Grouping and Functional Boosting through a simpler API and an administrative UI so you can integrate them into your application faster and more easily. 

You can get started today with a free 14 day trial of our hosted version or download the beta of the self-managed version.

Happy Searching!