简体   繁体   English

列字段上的索引不适用于ElasticSearch

[英]Indexing on column field is not working with ElasticSearch

I'm implementing ElasticSearch integration in my model : 我正在模型中实现ElasticSearch集成:

require 'elasticsearch/model'
class MissionDef < ActiveRecord::Base
  # field: name (String(40))
  # field: icon (String(2000))
  # field: definition (String)
  # field: public, boolean

  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks

  def as_indexed_json(options={})
    self.as_json(
     only: [:id, :name]
     )
  end
end

and In my Rails Console I did: 在我的Rails Console中,我做了:

MissionDef.import

MissionDef.first

MissionDef id: 226, ade_channel_key: "d403d658313e6c35ce", name: "Test Mission", icon: "/app/assets/images/badges/Showedup.png", definition: "{}", deleted_at: nil, created_at: "2015-08-04 11:30:08", updated_at: "2015-08-04 11:30:08", container_id: 883, public: true

My Query 我的查询

1) when I'm doing search with other field value other than name and id which is not indexed it gives me the search result. 1)当我使用名称和ID以外的其他字段值(未编入索引)进行搜索时,会得到搜索结果。 for eg: 例如:

result = MissionDef.search 'app' --- it works result.records.count => 1 结果= MissionDef.search'app'---它起作用result.records.count => 1

which should not be the case I guess. 我猜应该不是这种情况。

2) Missiondef.first.as_indexed_json => does not work properly it gives me o/p as whole object as JSON 2)Missiondef.first.as_indexed_json =>无法正常工作,它使我像JSON一样将o / p作为整个对象

{"id"=>226, "ade_channel_key"=>"d403d658313e6c35ce", "name"=>"Test Mission", "icon"=>"/app/assets/images/badges/Showedup.png", "definition"=>"{}", "created_at"=>Tue, 04 Aug 2015 11:30:08 UTC +00:00, "updated_at"=>Tue, 04 Aug 2015 11:30:08 UTC +00:00, "container_id"=>883, "public"=>true} {“ id” => 226,“ ade_channel_key” =>“ d403d658313e6c35ce”,“名称” =>“测试任务”,“ icon” =>“ / app / assets / images / badges / Showedup.png”,“定义” =>“ {}”,“ created_at” =>星期二,2015年8月4日11:30:08 UTC +00:00,“ updated_at” =>星期二,2015年8月4日,11:30:08 UTC +00:00,“ container_id“ => 883,” public“ => true}

I've not used the elasticsearch-rails gem before, but by default I know that elasticsearch will search entire documents, so if you only want to specify specific fields in your query. 我以前没有使用过elasticsearch-rails gem,但是默认情况下,我知道elasticsearch将搜索整个文档,因此,如果您只想在查询中指定特定字段。 So in your given example, the app is matching the icon field: / app /assets/images/badges/Showedup.png 因此,在您给出的示例中,该app与图标字段匹配:/ app /assets/images/badges/Showedup.png

Try specifying the fields you want to search - read more in their documentation here: https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-model/README.md#the-elasticsearch-dsl 尝试指定要搜索的字段-在此处阅读其文档中的更多信息: https : //github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-model/README.md#the-elasticsearch-dsl

So in this case it may be something like: 因此,在这种情况下,可能类似于:

result = MissionDef.search query: {match:  {name: "app" }}
result.records.count #=> should be 0 this time

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

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