尝试在Elasticsearch中设置max_gram和min_gram

2024-01-28

我尝试在 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 `

elasticsearch上没有索引文件,默认模板上也没有这个设置


我遇到过类似的问题,下面的错误消息清楚地解释了该问题。

[400] {“错误”:{“root_cause”:[{“类型”:“illegal_argument_exception”,“原因”:“ NGram Tokenizer 中 max_gram 和 min_gram 之间的差异必须是 小于或等于:1 https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html#_configuration_16但是[49]。这个限制可以通过设置 更改 [index.max_ngram_diff] 索引级别 设置。"}],"type":"illegal_argument_exception","re​​ason":" NGram Tokenizer 中 max_gram 和 min_gram 之间的差异必须是 小于或等于:1 https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html#_configuration_16但是[49]。这个限制可以通过设置 更改 [index.max_ngram_diff] 索引级别 设置。"},"状态":400}

基本上,默认情况下,NGram Tokenizer 中 max_gram 和 min_gram 之间的差异不能超过 1,如果您希望更改此设置,则需要在索引设置中通过添加以下设置来更改它。

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

下面是我的索引设置,您可以在其中看到我的差异47 in my max_gram and min_gram因此设定max_ngram_diff to 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:添加一个official https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html#_configuration_16Elastic 文档,解释了 max_gram 的默认长度为 2,min_gram 的默认长度为 1,因此它们之间的默认差异不能超过 1,因此出现异常。然后从同一个文档中摘取片段

索引级别设置index.max_ngram_diff控制最大 max_gram 和 min_gram 之间允许存在差异。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

尝试在Elasticsearch中设置max_gram和min_gram 的相关文章

随机推荐

  • matplotlib 标题中的 Latex 和文本

    我试图显示一个带有标题的图像 该标题将普通文本与几个 Latex 命令结合起来 plt imshow w1subtracted2 origin lower extent l max l max b max b max cmap color
  • 将 Unity 与 Eclipse 集成 - 通信?

    我通过以下步骤做到了 集成 Unity 和 Eclipse http forum unity3d com threads 71607 Integrating Unity and Eclipse 我可以使用 Android SDK 或 NDK
  • 带重定向的python请求

    正在尝试进行身份验证http 72 ru http 72 ru网站 注意到有一个重定向到https loginka ru auth https loginka ru auth 发现有 302 个带有数据形式的纯凭证的 POST 从 Chro
  • numpy.einsum 与 Fortran 或 C 相比是否高效?

    我写了一个 numpy 程序 非常耗时 经过profiling 我发现大部分时间都花在了numpy einsum 虽然numpy是LAPACK或BLAS的包装 但我不知道是否numpy einsum的性能与 LAPACK 或 BLAS 中的
  • 将 OS X Bash 脚本翻译为 Windows

    I use Hedge https hedge video 转移幻灯 https www magiclantern fm 在我的 Canon 5D Mark III 上拍摄的视频文件 在 OS X 上 我可以使用 Automator 设置
  • Xamarin iOS Javascript 和 C# 之间的通信

    我们正在实现一个应用程序 我们可以在 Javascript 和 C 之间进行通信 我们的 UIWebView 有一个按钮来调用一些本机功能 在 UIWebView 上 我在 ShouldStartLoad 上有一个处理程序 webView
  • Bake工具看不到SQLite3数据库中的表

    我正在尝试使用 CakePHP 2 1 1 使用 SQLite3 作为数据库构建一个简单的应用程序 为了节省时间 我尝试使用烘焙工具为下表创建模型 CREATE TABLE animals id integer primary key au
  • React - Internet Explorer 11 输入在第一次 onchange 后失去焦点

    我遇到了一个非常奇怪的问题 我无法理解 我目前正在使用 React 16 3 和 Antd 3 11 框架使用 create react app 并且我创建了一个表 该表在其标题列内呈现一个附加了 onChange 事件的组件 当我第一次关
  • “git pull”和“git fetch”有什么区别?

    想要改进这篇文章吗 提供此问题的详细答案 包括引用和解释为什么你的答案是正确的 不够详细的答案可能会被编辑或删除 两者有什么区别git pull https git scm com docs git pull and git fetch h
  • 詹金斯权限被拒绝

    我很抱歉来到这里询问这个问题 但我已经阅读了所有互联网试图找到解决方案 但我仍然遇到这个问题 我已经成功安装了 当我还有希望的时候就开始吧 jenkins 以便在我们的持续集成流程中使用它 我尝试从一个简单的例子开始 如下所示 pipeli
  • laravel 从带有实际点的文件夹名称加载视图

    我正在创建一个多域 Laravel 应用程序 因此我的视图文件位于每个域的单独文件夹中 例如 以下内容 return view pages SERVER SERVER NAME public home 应该加载一个视图 pages doma
  • Paypal自适应支付php

    我有这个问题 我已经按照这个教程 gt http www youtube com watch v rzRR1i F VA http www youtube com watch v rzRR1i F VA 设置完所有内容后 我在完成身份验证过
  • 计算 VS_KEY 容器名称

    如何计算 VS KEY 容器名称 它们通常是这样的 VS KEY 71E582524B5DDE29 我假设它是基于计算机名称的 但是如果我们运行的云服务在每次实例重新启动时随机更改计算机名称会怎样 当实例启动时 我们需要知道容器名称 以便我
  • C++ 运行时获取当前操作系统

    我需要弄清楚我的程序在运行时运行的操作系统 我正在使用 Qt 4 6 2 MinGW 和 Eclipse 以及 CDT 我的程序应在 Windows 或 Linux 上运行命令行 QProcess 现在我需要一种开关来根据操作系统运行不同的
  • 在 angularjs 中调用 $window.print() 会导致打印预览显示空白页

    我有一个非常奇怪的问题 当我在 angularjs 中调用 window print 时 我看到的只是左上角的日期 顶部的页面名称 右下角的页码和左下角的网址 然而 页面上没有其他内容 这很奇怪 因为常规页面有很多内容 我想这与我在页面上的
  • 如何使同一个 JSF 复合组件包含多次以拥有自己的 javascript 范围?

    我有一个像这样的 JSF 复合组件
  • 函数 write() 与数字表示法不一致

    考虑以下脚本 list of numbers lt as numeric for i in 1001999498 1002000501 list of numbers lt c list of numbers i write list of
  • 如何将列表写入Excel列?

    我有一个 Python 中的一些值的列表 想使用 openpyxl 将它们写入 Excel 电子表格列 到目前为止我尝试过 在哪里lstStat是需要写入 Excel 列的整数列表 for statN in lstStat for line
  • 简单:获取 Android 中发送的电子邮件的确认

    启动电子邮件意图后 如何确认电子邮件已发送或调用它的活动返回错误 Intent emailIntent new Intent Intent ACTION SEND emailIntent setType png image String s
  • 尝试在Elasticsearch中设置max_gram和min_gram

    我尝试在 Ubuntu 16 04 EC2 服务器上部署 Ruby on Rails 应用程序 但给出了有关 Elasticsearch 上 max gram 和 min gram 之间差异的错误 我还没有任何 Elasticsearch