我们目前正在运行一个带有2个索引的2节点Elasticsearch集群,并且运行良好(750k文档和1,110万文档)。
我们现在正尝试添加3540万个文档的新索引,并且搜索性能缓慢。术语过滤器大约需要2秒才能返回。
对应:
tire do
mapping _routing: { required: true, path: :order_id } do
indexes :id, type: 'string', index: :not_analyzed
indexes :order_id, type: 'string', index: :not_analyzed
[:first_name, :last_name, :company_name, :title, :email, :city, :state_region_province, :postal_code].each do |attribute|
indexes attribute, type: 'string', analyzer: 'keyword'
end
indexes :metadata, type: 'string'
indexes :clicks, type: 'integer', index: :not_analyzed, include_in_all: false
indexes :view_count, type: 'integer', index: :not_analyzed, include_in_all: false
indexes :sender, type: 'boolean', index: :not_analyzed, include_in_all: false
indexes :bounced, type: 'boolean', index: :not_analyzed, include_in_all: false
indexes :unsubscribed, type: 'boolean', index: :not_analyzed, include_in_all: false
end
end
搜索:
Model.tire.search(load: true, page: page, per_page: per_page, routing: order_id) do |search|
search.query do
match :metadata, query, type: 'phrase_prefix', max_expansions: 10
end if query.present?
search.filter :term, order_id: order_id
search.filter :term, sender: false
end
我正在做的搜索只是指定一个order_id进行过滤;返回结果大约需要2秒钟。我如何加快速度?
编辑:
我现在索引user_id并将其用作路由路径。我创建了一个包含30个分片的新索引,以测试过度分配。
编辑2:
使用30个分片,索引的性能更高,但仍然需要花费一秒钟的时间才能在第一个查询中返回数据。我不确定如何进一步加快速度或我做错了什么。
最佳答案
如果将对order_id
字段的分析切换为:keyword
会发生什么?从:
indexes :order_id, type: 'string', index: :not_analyzed
至:
indexes :order_id, type: 'string', index: :keyword
The docs说:
An analyzer of type keyword that “tokenizes” an entire stream as a single token. This is useful for data like zip codes, ids and so on.
似乎这适用于
order_id
。
关于ruby-on-rails - Elasticsearch术语过滤器速度慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14057631/