Modifying the resulting columns of an elasticsearch query

65 Views Asked by At

So I took on a larger project and am unsure where to find the code that modifies this. We have a database, where it's read as Essay -> Section -> figure, and we're trying to add a new column named 'video_url'. I believe this has to do with Denormalization however I'm not entirely sure.

Here's the Essay model:

class Essay
  include ActiveModel::Model
  include ActiveModel::Serialization
  include Draper::Decoratable
  include Import::HtmlEssay
  include Searchable

  FACETS = %w(author)
  FULLTEXT_FIELDS = %w(title sections.title sections.body sections.figures.caption)

  def self.define_mappings!
    mapping mapping_options do
      analyzer = I18n.locale == :tr ? :turkish : :snowball

      indexes :author, index: :not_analyzed
      indexes :publication_id, index: :not_analyzed
      indexes :sequence, type: 'long'
      indexes :title, analyzer: analyzer
      indexes :sections do
        indexes :title, analyzer: analyzer
        indexes :body, analyzer: analyzer
        indexes :figures do
          indexes :caption, analyzer: analyzer
        end
      end
    end
  end

  class Query
    include Searchable::Query

     def sort
       [
         { publication_id: { order: 'asc'}},
         { sequence: { order: 'asc' }}
       ]
     end
  end
end

Right now it just shows [Mash caption, credit, figure(#), url]. I want to append video_url to that which is part of the Image model (which is where we're pulling the url from) however I'm not sure how this works and have had trouble with it. The only relevant gem I think they're using is elasticsearch-model, however I've gone through a bunch of their stuff and am still not sure.

The control as well (although nothing's really happening here) is as follows:

class EssaysController < SearchBaseController
  def show
    @essay = Essay.find(params[:id]).decorate
  end
end

Honestly even if you don't know the answer if you can tell me where even things like "FULLTEXT_FIELDS" var are coming from that'd be very helpful, and I can edit this to add other sections of code if need be. I just really need to figure out how to add the video_url column to the results, it's in elasticsearch and can be accessed with other methods but just isn't showing up here.

1

There are 1 best solutions below

0
On

So I ended up finding there was another folder inside /models/concerns/import/*, which contained more information on the database setup. I'm not sure what gem they're using/why it's set up this way but I'll update this answer when I learn more about it.