How to enrich/auto-generate fields before index?

I'm fairly new to elasticsearch, so apologies if this is a dumb question...Is there a way to automatically generate a field based on other fields, prior to the document being indexed? I would like to generate a string based on a couple other fields in the document, which will be used for ordering records with equal scores. Here's a simple example of what I'm trying to accomplish, and hoping is possible, somehow:

  file_name: { type: 'text' },
  directory: { type: 'nested', properties: { name: 'text' } },
  full_path: { type: 'keyword', template: '${"/") + "/" + file_name}` }

So, I know this is a rough example but I'm hoping it gets my point across. In this example the "directory" field contains multiple values - 1 value for each parent directory, so an example document which would represent the file "/home/redec/foo.log" would look like this:

  file_name: 'foo.log',
  directory: [ { name: 'home' }, { name: 'redec' } ],
  full_path: '/home/redec/foo.log'

Obviously I realize I can generate the full_path value before inserting the document, but I would like to do it on the elasticsearch side so that I can do a targeted update to update the name of a parent directory and have the full_path get automatically updated (so I don't have to individually update every document one by one)

I realize sorting/ordering by a string field is not exactly in elasticsearch's core competency, and does not seem to be a common thing to do so I'm kinda in fringe territory here, but I'm hoping there's some mechanism that can be used to accomplish this. Any help/advice is appreciated! Thanks! :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.