I am using Elasticsearch and the Elasticsearch Rails gem. I have two models that are associated via ActiveRecord and I am trying to index and search them with Elasticsearch.
Here is my store model
store.rb
has_many :addresses
has_many :jobs
def as_indexed_json
self.as_json(include: {
customer: { include: { addresses: {}, jobs: {} } },
vendors: {}
})
end
settings index: { number_of_shards: 1 } do
mapping dynamic: 'false' do
indexes :id
indexes :store_number
indexes :manager
indexes :customer do
indexes :first_name
indexes :addresses do
indexes :city
indexes :state
end
indexes :jobs do
indexes :job_number
end
end
end
end
here is my address model:
def as_indexed_json
end
settings index: { number_of_shards: 1 } do
mapping dynamic: 'false' do
indexes :city
indexes :state
end
end
I am also using Searchkit as my front end UI. Searchkit is able to aggregate and display all of the attributes that are in the store model (store number and manager for example). However, it is not able to view the nested items. In other words I cannot aggregate and retrieve the job_numbers under jobs which is under customer. I am able to view the customers name, etc. I have tried using type: "nested" next to jobs and all the other objects, but that doesn't make a difference. I have tried adjusting the as_indexed_json without any luck as well. Any one have any idea on this? I am stumped on this one.