user3206440
user3206440

Reputation: 5059

Elasticsearch not indexing field named “type” in DB

With single table inheritance, facing an issue with indexing a specific column named "type" in a table. The table has two cols of interest (among others), "product_name" and "type". The "product_name" field is indexed properly , the "type" field is not getting indexed at all - any ideas on troubleshooting this? Using elasticsearch-ruby gem with Ruby on Rails.

Upvotes: 1

Views: 601

Answers (1)

Shadwell
Shadwell

Reputation: 34784

Assuming you are using elasticsearch-model to index your rails models the type column is excluded by default. Basically, as_json gets called on your model to provide fields for elasticsearch to add to the index.

In order to add fields to the index that aren't returned in as_json you'll need to provide an implementation of as_indexed_json. The process is described under Model serialization in the readme.

You'll probably need to do something like:

def as_indexed_json(options = {})
  as_json(methods: :type)
end

This will add the type to the json that is used to index the object.

Upvotes: 5

Related Questions