concept function query in category elasticsearch

appears as: function query, Function queries
Relevant Search: With applications for Solr and Elasticsearch

This is an excerpt from Manning's book Relevant Search: With applications for Solr and Elasticsearch.

You’ve seen through the | symbol that the “max” of two fields is often taken. There’s also often a coord factor that directly punishes compound matches missing some of their components (coord multiplies the resulting dot product by <the number of matches> / <the total query terms>). Many of the compound queries you’ll encounter will perform various operations on the underlying queries, such as taking a max, summing, or taking a product. You also have tremendous freedom to arbitrarily calculate or boost scores with your own function queries that might combine match (or other) scores with other arbitrary factors. You’ll explore many of these strategies in future chapters.

Function queries give you direct control of the ranking function. You combine the base query and any boost queries in mathematically arbitrary forms. There’s no baked-in “formula” as in Boolean queries. Therefore, function queries can’t cleanly be categorized as multiplicative or additive. Function queries are simply math! Given the lower level of control, there are things only function queries can accomplish.

Let’s get back to our problem. Where were we? Oh, right! You have an important search problem to solve with hordes of Trek fans raring to break down your door. Better choose a solution fast! Do you go through door A and solve your problem by applying an additional Boolean clause? Or do you go through door B and begin to get your hands dirty with function queries? Let’s see the consequences of both decisions.

7.2.5. Hands-on with function queries: simple multiplicative boosting

Let’s switch back to our Star Trek example to get our hands dirty with function queries in the Query DSL. You need to see a function query in the context of something basic before tackling larger mathematical problems. To ease you in, we’ll give you a starting point: solving our Star Trek title boost. Later in this chapter, you’ll begin to tackle a larger, more challenging problem that extends beyond the simple function presented here.