弹性搜索需要*所有*关联被映射? [英] Elasticsearch requires*all* associations to be mapped?

查看:183
本文介绍了弹性搜索需要*所有*关联被映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个巨大的模型(它基本上是我的整个应用程序)。我在这个模型上有7个以上的关联,包括很多到许多,通过=>等。这个模型还有一些简单的属性(标题,url等等)。



我唯一关心索引的是3或4个简单属性(标题,URL,描述,类别)。其余的我不在乎。



当我使用 load:true 时,一切都会很好因为我把所有的东西都打破了。解决这个问题的唯一方法是,进入并添加复杂的映射:触摸,触摸回调等每个关联?



我希望我'理解这个错误,因为这将是一个巨大的代码,只能搜索3或4个简单的属性。



我不知道我在说什么,但可以我可能搜索弹性搜索索引,但是返回一个ID的列表,只是循环使用正常的轨道方式?



谢谢!

解决方案

我不知道轮胎是如何内部工作的,但据我从文档中了解到,当加载 option是true,它加载数据库中的每个记录。这就是为什么我不认为你想在生产中使用它。没有这个选项,轮胎会从弹性搜索中检索信息,因为您应该将大部分要显示的数据存储在弹性搜索中。您可能需要向弹性搜索添加更多存储的信息。您可以配置要存储在映射中的字段,否则您总是拥有字段,这正是您索引的JSON文档。



您最后一个问题的答案是肯定的。您可以选择要从弹性搜索中返回的字段,而不是获取返回整个来源。在你的情况下,如果我理解正确,你将配置唯一的id字段。我不知道如何使用轮胎,但是在弹性搜索请求方面,您可以在这样的URL中执行:

  curl localhost:9200 / _search?fields = id -d'{
query:{
match_all:{}
}
}'

或直接在您的查询中如下:

  {
fields:[id],
query:{
match_all:{}
}
}


I have one massive model (It basically is my entire app). I have 7 or more associations on this model, including many to many, :through => etc. This model also has a few simple attributes (title, url, and so on).

The only thing I care about indexing are those 3 or 4 simple attributes (title, url, description, category). The rest I don't care about.

Everything works perfectly when I use load: true, but as soon as I turn that off everything breaks. The only way to fix this it seems is to go in and add complex mappings, :touch, :touch callbacks and so on for every single association?

I hope I'm understanding this wrong because this would be a huge amount of code only to search through 3 or 4 simple attributes.

I have no idea what I'm talking about but could I maybe search through the elasticsearch index, but return a list of ID's, and just loop through those in the normal rails way?

Thanks!

解决方案

I don't know exactly how tire works internally but as far as I understood from the documentation when the load option is true it loads every record from the database. That's why I don't think you want to use it in production. Without that option Tire retrieves the information from elasticsearch, since you should have most of the data you want to display stored in elasticsearch. Probably you need to add more stored information to elasticsearch. You can do it configuring the field that you want to store in your mapping, otherwise you always have the source field in elasticsearch, which is exactly the JSON document you indexed.

The answer to your last question is yes. You can select which fields you want back from elasticsearch instead of getting back the whole source. In your case if I understood correctly you'd configure the only id field. I don't know how to do it with Tire but in terms of elasticsearch request you can do it either in the url like this:

curl localhost:9200/_search?fields=id -d '{
  "query" : {
    "match_all" : {}
  }
}'

or directly in your query like this:

{
    "fields" : ["id"],
    "query" : {
        "match_all" : {}
    }
}

这篇关于弹性搜索需要*所有*关联被映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆