Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get results weighted by references from ElasticSearch

I have a dataset consisting of Notes referencing other Notes.

{id:"aaa", note: "lorem ipsum", references: ["ccc"]},
{id:"bbb", note: "lorem ipsum", references: ["aaa","ccc"]},
{id:"ccc", note: "lorem ipsum", references: ["bbb"]},

I want elastic search to use the references to weight the results, so in this case if I search for lorem I should get id "ccc" back since it has the most references. According to their docs, their graph solution does exactly this, but I also see examples where they are doing similar things.

But no explanation of how this is mapped to the Index. So my question is: how does one set up an ES index that uses references (indices)?

like image 349
Jesper Bylund Avatar asked May 06 '20 17:05

Jesper Bylund


People also ask

How do I retrieve more than 10000 results events in Elasticsearch?

By default, you cannot use from and size to page through more than 10,000 hits. This limit is a safeguard set by the index. max_result_window index setting. If you need to page through more than 10,000 hits, use the search_after parameter instead.

How does Elasticsearch calculate score?

Before scoring documents, Elasticsearch first reduces the set of candidate documents by applying a boolean test that only includes documents that match the query. A score is then calculated for each document in this set, and this score determines how the documents are ordered.

How do I get all records in Elasticsearch?

Introduction. You can use cURL in a UNIX terminal or Windows command prompt, the Kibana Console UI, or any one of the various low-level clients available to make an API call to get all of the documents in an Elasticsearch index. All of these methods use a variation of the GET request to search the index.


1 Answers

Other answers gave some clues, but then @7379490 provided the answer in another channel:

There is no way of doing this directly in ES. There are two possible solutions: pre calculate references and pass them into ES by mapping a new value to the document.

Or aggregate and use aggregation to sort the response:

{
  "query": {
    "function_score": {
      "query": {
        "match": {
          "note": "lorem"
        }
      },
      "aggs": {
      "references":{
        "terms" : {
          "field" : "references.keyword",
          "order": { "_count": "desc" }
        }
      }
    }
  }
}
like image 196
Jesper Bylund Avatar answered Sep 28 '22 02:09

Jesper Bylund