Coder Social home page Coder Social logo

kvasnevskyi / elasticsearch-collapse-extension Goto Github PK

View Code? Open in Web Editor NEW

This project forked from anti-social/elasticsearch-collapse-extension

0.0 1.0 0.0 92 KB

Elasticsearch collapsing extension made as a rescore

License: Apache License 2.0

Kotlin 5.52% Java 94.48%

elasticsearch-collapse-extension's Introduction

What does this plugin allows to do?

You can collapse search results based on field values:

ext:
  collapse:
    field: model_id
    size: 10000  # window for collapsing
    shard_size: 1000  # truncate after collapsing on a shard
    sort:
      price: asc

Or using a script to choose the best hit in a group:

ext:
  collapse:
    field: model_id
    size: 10000
    shard_size: 1000
    sort:
      _script:
        type: number
        script:
          lang: painless
          source: |
            float base = 0.0;
            float dev = randomScore(params.seed, '_seq_no') * 0.1;
            if (doc['grade'].value < 4) {
                base = 1000.0;
            }
            float price = doc['price'].value;           
            return base + Math.log1p(price * (1.0 + dev));
          params:
            seed: 123456  # seed из сессии
        order: asc

Why not use existing solutions?

There are 2 solution for collapsing out of the box but they both have some drawbacks:

Firstly it collapses all the documents that don't have value for collapsing into a single hit. This can be bypassed populating some random value for such documents.

And what's more important it does not support rescoring which we use a lot for deboosting products from the same company:

collapse cannot be used in conjunction with scroll, rescore or search after.

This kind of aggregation is not recommended to use for collapsing:

We do not recommend using top_hits as a top-level aggregation. If you want to group search hits, use the collapse parameter instead.

Also we need to populute documents with some random values.

Although top hits aggregation calls rescore phase, its parent aggregation doesn't. So we cannot sort groups using rescored score.

elasticsearch-collapse-extension's People

Contributors

anti-social avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.