简体   繁体   English

带有Elastic gem的带有胎面宝石的嵌入式文档的索引字段?

[英]Index field on embedded documents with tire gem for ElasticSearch?

How do I index a specific field on an embedded document using the tire gem for ElasticSearch's syntax? 如何使用Tire gem为ElasticSearch的语法索引嵌入式文档中的特定字段?

I have tried the following for my Question model which embeds many Answers and I would like only the description field on the Answer model to be indexed. 我已经为嵌入许多答案的Question模型尝试了以下内容,并且我只希望对Answer模型上的描述字段建立索引。

Searching for text that should match a stored answer's description is returning no results. 搜索与存储的答案说明匹配的文本不会返回任何结果。 I am using Mongoid as my MongoDB driver by the way. 顺便说一下,我正在使用Mongoid作为MongoDB驱动程序。

 mapping do
    indexes :id, :index => :no
    indexes :created_at, :index => :no
    indexes :updated_at, :index => :no
    indexes :title, :index => :analyzed
    indexes :description, :index => :analyzed
    indexes :page_views, :index => :no
    indexes :asker, :index => :no
    indexes :tags, :index => :analyzed
    indexes :answers do
      indexes :id, :index => :no
      indexes :description, :index => :analyzed
      indexes :answerer, :index => :no
      indexes :created_at, :index => :no
      indexes :updated_at, :index => :no
    end
    indexes :comments, :index => :no
    indexes :votes, :index => :no
    indexes :up_count, :index => :no
    indexes :down_count, :index => :no
    indexes :vote_score, :index => :no
  end

I think you need to specify the type of each field before you can set the "index" parameter. 我认为您需要先指定每个字段的类型,然后才能设置“ index”参数。 (I might be wrong) (我可能错了)

I think this will not work: 我认为这行不通:

"properties": {
  "description": {
    "index": "analyzed"
  }
}

Try this instead: 尝试以下方法:

"properties": {
  "description": {
    "type": "string",
    "index": "analyzed" //not really needed as the default is analyzed
  }
}

Can you please check your mapping by using: 您能否使用以下方法检查您的映射:

curl -XGET 'http://localhost:9200/your_index/your_type/_mapping'

Post the output and we will see if elasticsearch is configured correctly. 发布输出,我们将查看elasticsearch是否正确配置。

Good luck! 祝好运!

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

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