Elasticsearch: should bool query with filters

In the process of migration from Elasticsearch version 2 to Elasticsearch version 5, we also want to change the traditional order from “the most recent” to more accurate relevance search, using the score that use elasticsearch.

The new search its a should bool query, basically, this type of query score each hit of the bool query with a score:


  query:  {
    bool:  {
     should: [
      should_query1,
      should_query2,
      should_query3
     ]
   }
 }

In this type of query when a doc match any of the should_query it gets a score. What happens if you want to filter the docs? you simple add a filter to the query:


  query:  {
    bool:  {
     should: [
      should_query1,
      should_query2,
      should_query3
     ],
     filter: [ 
        myfilter
     ]
   }
 }

The problem is that the filter returns all the fields that match the filter with a score of 0, not only the ones that match any of the should query. So if the filter returns, say, 1000 docs, and the should query only scores 100 of them, you has 1000 records, 900 of them with score 0. Also if you return a lot of docs, the query is really slow.

To solve this problem, elasticsearch has the option “minimum_should_match” that indicates the minimum query in the should bool query that need to match in order to take into account in the result.

 

Using Kafka from CFML

Another year going to cfcamp, the cfml conference in Munich, first time as speaker. It’s also the first time I speak in english in public, a little nervious  at the beginning but confortable after a while. I hope the liseners could understand me more or less 🙂

I have done a quick intro to Apache Kafka, that we at work are using in production since february, how to use it in CFML throught the jar kafka client and how we manage the “consumers” and “consumers groups” with a web panel in cfml.

I have  prepared two repo to show it:

  • First, one with a simple producer and a consumer and how to use it:

https://github.com/davidsf/cfml-kafka

  • Second one, a little coldbox app showing with a little panel that can launch consumers from a configured consumer group:

https://github.com/davidsf/cfml-kafka-panel

Fill free to explore it and open a issue if you have any problem.

Also the presentation:

Kafka CFCamp 2017