Contextual field values in ElasticSearch

36 views Asked by At

I am indexing a library in ElasticSearch that's searched by lots of different users from lots of different organisations.

Organisations can rename and add notes to books just within the context of their organisation, and users can further rename or add notes to books just within the context of their account.

Books will have global "title" and "notes" fields, but how can I store the contextual name and notes?

Is there native ElasticSearch functionality to support contextual document fields like this? I am looking at using runtime fields to calculate a users contextual title and notes for each book during a search, but the contextual data would need to be saved somewhere.

For example, the docs will look like:

PUT /books
{
  "mappings": {
    "properties": {
      "id":  { "type": "binary" },
      "title":  { "type": "keyword" },
      "notes":     { "type": "text" },
      "fulltext": { "type:": 'text" },
    }
  }
}

Contextual Example

Say we have one book { title: "Eragon", Notes: "" }. Organisation 1 adds the note "contains dragons" and User 1 renames it to "Blue book".

When any user from Organisation 1 does a search for "contains dragons" it should return the book, but not for any user outside of that organisation. When user 1 searches for "Blue book" they should see the book, and a search for "Eragon" would yield no results (the opposite would apply for any other user). If user 1 is part of organisation 1, then they should be able to see the book searching for either "contains dragons" or "Blue book"

Other users from outside of organisation 1 would still only be able to search for the book using it's default values which is in this case title "Eragon" with no notes.

0

There are 0 answers