简体   繁体   English

Elasticsearch不索引数据库中名为“ type”的字段

[英]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". 该表有两个感兴趣的列(其中包括)“ product_name”和“ type”。 The "product_name" field is indexed properly , the "type" field is not getting indexed at all - any ideas on troubleshooting this? “ product_name”字段已正确建立索引,“ type”字段根本未建立索引-有关对此进行故障排除的任何想法? Using elasticsearch-ruby gem with Ruby on Rails. 在Ruby on Rails中使用elasticsearch-ruby gem。

Assuming you are using elasticsearch-model to index your rails models the type column is excluded by default. 假设您正在使用elasticsearch-model索引您的rails模型,则默认情况下会排除类型列。 Basically, as_json gets called on your model to provide fields for elasticsearch to add to the index. 基本上,在模型上调用as_json以提供字段供as_json添加到索引中。

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 . 为了将未在as_json返回的字段添加到索引中,您需要提供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. 这会将类型添加到用于索引对象的json中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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