简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM