Saya mencoba menggunakan aplikasi Ruby on Rails di server Ubuntu 16.04 EC2 tetapi memberikan kesalahan tentang perbedaan antara max_gram dan min_gram di Elasticsearch, saya belum memiliki pengalaman dengan Elasticsearch jadi saya benar-benar tersesat di sini dan saya butuh panduan untuk melakukan ini dan mempelajari cara mengaturnya untuk menghindari masalah ini di masa mendatang.

Pertama kali saya melakukan penyebaran ada kesalahan menolak koneksi ke localhost:9200 jadi saya harus memeriksa apakah layanan berjalan dan bahkan memeriksa firewall dan pada akhirnya saya harus melakukan instalasi bersih dan mengkonfigurasi semuanya di elasticsearch. yml dan sekarang sedang berjalan dan berfungsi tetapi ketika saya mencoba untuk menyebarkan lagi memberi saya kesalahan, melakukan banyak pencarian di internet ada banyak dokumentasi tetapi saya masih tidak mendapatkan tempat untuk mengatur nilai-nilai ini.

Ini adalah kesalahan yang saya dapatkan di log:

-----> 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 `

Tidak ada file indeks di elasticsearch dan tidak ada pengaturan ini pada template default

5
Cesar Rodriguez 7 Agustus 2019, 16:44

2 jawaban

Jawaban Terbaik

Saya telah menghadapi masalah serupa dan pesan kesalahan di bawah ini dengan jelas menjelaskan masalah tersebut.

[400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"The perbedaan antara max_gram dan min_gram di NGram Tokenizer harus kurang dari atau sama dengan: 1 tetapi [49]. Batas ini dapat diatur oleh mengubah level indeks [index.max_ngram_diff] setting."}],"type":"illegal_argument_exception","reason":"The perbedaan antara max_gram dan min_gram di NGram Tokenizer harus kurang dari atau sama dengan: 1 tetapi [49]. Batas ini dapat diatur oleh mengubah level indeks [index.max_ngram_diff] pengaturan."},"status":400}

Pada dasarnya, secara Default, perbedaan antara max_gram dan min_gram di NGram Tokenizer tidak boleh lebih dari 1 dan jika Anda ingin mengubahnya, maka dalam pengaturan indeks Anda, Anda perlu mengubahnya dengan menambahkan pengaturan di bawah ini.

"max_ngram_diff" : "50" --> you can mention this number accoding to your requirement.

Di bawah ini adalah pengaturan indeks saya, di mana Anda dapat melihat saya memiliki perbedaan 47 di max_gram dan min_gram saya, maka setel max_ngram_diff ke 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"
        }
    }
} 

Edit: Menambahkan resmi Dokumentasi elastis, yang menjelaskan bahwa panjang default max_gram adalah 2 dan min_gram adalah 1, maka perbedaan default antara ini tidak boleh lebih dari 1, maka pengecualian. Dan kemudian cuplikan dari dokumen yang sama

Pengaturan tingkat indeks index.max_ngram_diff mengontrol perbedaan maksimum yang diperbolehkan antara max_gram dan min_gram.

8
user156327 7 Agustus 2019, 16:49

Seseorang juga dapat menggunakan templat indeks untuk menerapkan pengaturan secara otomatis ke semua indeks baru:

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
      }
    }
  }
}
'

Template tidak akan dihapus dengan menghapus setiap indeks, tetapi harus dihapus secara manual:

curl -X DELETE "localhost:9200/_index_template/template_1
2
HeikoG 20 April 2021, 14:48