elastic / elasticsearch-rails

Elasticsearch integrations for ActiveModel/Record and Ruby on Rails
Apache License 2.0
3.07k stars 793 forks source link

Mapping Two Ruby on Rails Models with Different Attribute Names to a Shared Elasticsearch Index using 'elasticsearch-rails' #1059

Closed daalvand closed 1 year ago

daalvand commented 1 year ago

Hello,

I'm using the 'elasticsearch-rails' gem and trying to map two Ruby on Rails models, let's call them A and B, into a shared Elasticsearch index for efficient searching. The challenge I'm facing is that both models have similar attributes, like 'title' for Elasticsearch, but they are named differently ('about' in model A and 'name' in model B).

I would appreciate any guidance on how to create a unified structure in Elasticsearch that handles this mapping effectively. Specifically, I'm looking for advice on how to:

  1. Map the 'about' attribute from model A and the 'name' attribute from model B to the 'title' field in Elasticsearch.
  2. Configure the 'elasticsearch-rails' gem to properly index and search this shared index while considering the attribute differences.

Thank you in advance for any assistance you can provide!