Ces*_*uez 5 n-gram elasticsearch elasticsearch-analyzers
我试图在 Ubuntu 16.04 EC2 服务器上部署一个 Ruby on Rails 应用程序,但给出了一个关于 Elasticsearch 上 max_gram 和 min_gram 之间差异的错误,我还没有任何使用 Elasticsearch 的经验,所以我完全迷失在这里,我需要一些指导这样做并学习如何设置它以避免将来出现此问题。
我第一次进行部署时出现拒绝连接到 localhost:9200 的错误,因此我必须检查服务是否正在运行,甚至检查防火墙,最后我必须进行全新安装并在 elasticsearch 上配置所有内容。 yml 现在正在运行和工作,但是当我尝试再次部署时出现错误,在互联网上进行了大量搜索,有很多文档,但我仍然不知道在哪里设置这些值。
这是我在日志中得到的错误:
-----> Migrating database...
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
[400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"The difference between max_gram and min_gram in NGram Tokenizer must be less than or equal to: [1] but was [49]. This limit can be set by changing the [index.max_ngram_diff] index level setting."}],"type":"illegal_argument_exception","reason":"The difference between max_gram and min_gram in NGram Tokenizer must be less than or equal to: [1] but was [49]. This limit can be set by changing the [index.max_ngram_diff] index level setting."},"status":400}
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/elasticsearch-transport-6.0.2/lib/elasticsearch/transport/transport/base.rb:205:in `__raise_transport_error'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/elasticsearch-transport-6.0.2/lib/elasticsearch/transport/transport/base.rb:323:in `perform_request'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/elasticsearch-transport-6.0.2/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/elasticsearch-transport-6.0.2/lib/elasticsearch/transport/client.rb:131:in `perform_request'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/elasticsearch-api-6.0.2/lib/elasticsearch/api/namespace/common.rb:21:in `perform_request'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/elasticsearch-api-6.0.2/lib/elasticsearch/api/actions/indices/create.rb:86:in `create'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/searchkick-3.0.2/lib/searchkick/index.rb:16:in `create'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/searchkick-3.0.2/lib/searchkick/index.rb:203:in `create_index'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/searchkick-3.0.2/lib/searchkick/index.rb:270:in `reindex_scope'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/searchkick-3.0.2/lib/searchkick/index.rb:196:in `reindex'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/searchkick-3.0.2/lib/searchkick/model.rb:59:in `searchkick_reindex'
/home/deploy/catalogindustry/releases/20190807135404/db/migrate/20180405153226_validated_true.rb:4:in `change'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:789:in `exec_migration'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:773:in `block (2 levels) in migrate'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:772:in `block in migrate'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:771:in `migrate'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:951:in `migrate'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:1232:in `block in execute_migration_in_transaction'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:1302:in `ddl_transaction'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:1231:in `execute_migration_in_transaction'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:1203:in `block in migrate_without_lock'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:1202:in `each'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:1202:in `migrate_without_lock'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:1150:in `block in migrate'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:1319:in `with_advisory_lock'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:1150:in `migrate'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:1006:in `up'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/migration.rb:984:in `migrate'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/tasks/database_tasks.rb:163:in `migrate'
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/railties/databases.rake:58:in `block (2 levels) in '
/home/deploy/catalogindustry/shared/bundle/ruby/2.3.0/gems/rake-12.3.1/exe/rake:27:in `'
/home/deploy/.rbenv/versions/2.3.1/bin/bundle:23:in `load'
/home/deploy/.rbenv/versions/2.3.1/bin/bundle:23:in `
Run Code Online (Sandbox Code Playgroud)
elasticsearch 上没有索引文件,默认模板上没有关于此设置的任何内容
我遇到了类似的问题,下面的错误消息清楚地解释了这个问题。
[400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"NGram Tokenizer 中 max_gram 和 min_gram 的差值必须小于或等于:1但为 [49 ]. 这个限制可以通过改变[index.max_ngram_diff] 索引级别设置来设置。"}],"type":"illegal_argument_exception","reason":"NGram Tokenizer 中 max_gram 和 min_gram 之间的差异必须小于或等于:1但为 [49]。可以通过更改 [index.max_ngram_diff] 索引级别设置来设置此限制。"},"status":400}
基本上,默认情况下,NGram Tokenizer 中 max_gram 和 min_gram 之间的差异不能超过 1,如果您想更改它,那么在您的索引设置中,您需要通过添加以下设置来更改它。
"max_ngram_diff" : "50" --> you can mention this number accoding to your requirement.
Run Code Online (Sandbox Code Playgroud)
下面是我的索引设置,在这里你可以看到我有一个区别47,我max_gram并min_gram因此设置max_ngram_diff到50。
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"prefix": {
"type": "custom",
"filter": [
"lowercaseFilter"
],
"tokenizer": "edgeNGramTokenizer"
}
},
"tokenizer": {
"edgeNGramTokenizer": {
"token_chars": [
"letter",
"digit"
],
"min_gram": "1",
"type": "edgeNGram",
"max_gram": "40"
},
"loginNGram": {
"type": "nGram",
"min_gram": "3",
"max_gram": "50"
}
}
},
"number_of_shards": "1",
"number_of_replicas": "0",
"max_ngram_diff" : "50"
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:添加官方Elastic 文档,其中解释了 max_gram 的默认长度为 2,min_gram 的默认长度为 1,因此它们之间的默认差异不能超过 1,因此例外。然后从同一个文档中摘录
索引级别设置 index.max_ngram_diff 控制 max_gram 和 min_gram 之间的最大允许差异。
人们还可以使用索引模板将设置自动应用于所有新索引:
curl -X PUT "localhost:9200/_index_template/template_1?pretty" -H 'Content-Type: application/json' -d'
{
"index_patterns": [
"*"
],
"template": {
"settings": {
"index": {
"max_ngram_diff": 50
}
}
}
}
'
Run Code Online (Sandbox Code Playgroud)
删除每个索引不会删除模板,但必须手动删除:
curl -X DELETE "localhost:9200/_index_template/template_1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6888 次 |
| 最近记录: |