小编Mon*_*odr的帖子

什么是Elasticsearch-py等同于别名操作?

我正在尝试使用elasticsearch-dsl实现多重索引方法.基本上有两个步骤:

1.创建别名:

PUT /tweets_1/_alias/tweets_search 
PUT /tweets_1/_alias/tweets_index 
Run Code Online (Sandbox Code Playgroud)

2.必要时更改别名:

POST /_aliases
{
  "actions": [
    { "add":    { "index": "tweets_2", "alias": "tweets_search" }}, 
    { "remove": { "index": "tweets_1", "alias": "tweets_index"  }}, 
    { "add":    { "index": "tweets_2", "alias": "tweets_index"  }}  
  ]
}
Run Code Online (Sandbox Code Playgroud)

我只能使用elasticsearch-py(而不是dsl)实现第1步:

from elasticsearch.client import IndicesClient
IndicesClient(client).("tweets_1", "tweets_search")
IndicesClient(client).("tweets_1", "tweets_index")
Run Code Online (Sandbox Code Playgroud)

我不知道如何为第2步做到这一点.那么,elasticsearch-dsl(或者至少在elasticsearch-py中)的等价物是什么?

python elasticsearch elasticsearch-dsl elasticsearch-py

7
推荐指数
1
解决办法
3169
查看次数

如何使用不同的列作为外键强制has_many关联

陷入困境 - 乍一看 - RoR中的简单问题.我相信这很容易,但是在SO中没有人回答太多帮助我.

我有两个ActiveRecord模型:Foo有很多Bars:

class Foo < ApplicationRecord
    has_many :bars
end

class Bar < ApplicationRecord
  belongs_to :foo
end
Run Code Online (Sandbox Code Playgroud)

这就像一个魅力.但我想使用另一个Fooforeign_key 字段.默认是foo_id我想custom_id用作我的外键.所以我尝试了这个(因为网上建议的解决方案很多):

class Foo < ApplicationRecord
    has_many :bars, :foreign_key => 'custom_id', :class_name => 'Bars'
end

class Bars < ApplicationRecord
  belongs_to :foo, :class_name => 'Foo'
end
Run Code Online (Sandbox Code Playgroud)

但这不起作用.即ActiveRecord的不断结合FooBars使用foo_id.

注意:在Foo中包含self.primary_key ='custom_id'可以部分工作.但我认为这不是一个好主意.我想保持foo_id为主键

更新:

鉴于反馈 - 谢谢你们 - 我在这里上传了这个例子https://github.com/montenegrodr/temporary_repository_ror:

更新#2:

答案不符合上述问题.为什么测试失败,我的假设是它不会失败.

更新#3: …

activerecord ruby-on-rails ruby-on-rails-5

6
推荐指数
1
解决办法
880
查看次数

通过ElasticSearch DSL python包装器创建索引时如何在索引级别设置ignore_malformed?

根据docs,这应该足够了:

"settings": {
    "index.mapping.ignore_malformed": true 
  }
Run Code Online (Sandbox Code Playgroud)

但是如何在 python 包装器上实现这一点呢?我当前的代码如下所示:

from elasticsearch_dsl import Index

index = Index('my_index', my_conn)
index.settings(
     number_of_shards=ES_NUMBER_OF_SHARDS,
     number_of_replicas=ES_NUMBER_OF_REPLICAS
)
index.create()
Run Code Online (Sandbox Code Playgroud)

python python-2.7 elasticsearch elasticsearch-dsl elasticsearch-py

4
推荐指数
1
解决办法
2004
查看次数