ruby-on-rails - Elasticsearch more_like_this查询异常

标签 ruby-on-rails curl elasticsearch multi-index

尝试在我的RoR应用程序中使用ElasticSearch more_like_this查询。我为不同的环境设置了不同的索引,分别具有search_development和search_staging。

在登台环境上(通过CURL或通过Rails控制台)执行MLT查询时,一切似乎都很好-返回了记录。

在开发环境中进行相同操作时,结果集始终为空。我认为这与数据版本有关,因此我尝试从头开始重新创建索引。现在,完成此操作后,查询MLT会引发异常:

Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[UvOf1vxTR6WNICxTzIdJ1g][search_development][2]: SearchParseException[[search_development][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"more_like_this\":{\"ids\":[\"1\"],\"fields\":[\"title\",\"description\"]}}}]]]; nested: QueryParsingException[[search_development] ambiguous type for item with id: 1 and index: search_development]; }

通过CURL和Rails控制台都会发生这种情况。相同的确切查询在登台索引上运行良好。检查时,记录在索引中,数据也在其中。 query_string查询可以像以前一样正常工作。

显然,elasticsearch或MLT查询的多索引部分缺少某些内容,因为在重新创建索引之前,该查询未返回结果(而相同的精确查询在暂存索引上可以很好地工作)。我必须补充一点,登台索引具有超过一千条记录,而开发只有14条记录。

查询是:
curl -XGET 'http://asdf:9200/search_development/_search' -d '{ "query": {"more_like_this": {"ids": ["1"], "fields": ["title","description"]}} }'

最佳答案

两个潜在的问题:

  • 您未在请求URL中指定类型。要搜索单个类型(这将使“id”字段明确),请在网址中使用另外一个参数:
  • curl -XGET 'http://asdf:9200/search_development/my_type/_search' -d '{ "query": {"more_like_this": {"ids": ["1"], "fields": ["title","description"]}} }'
  • 如果确实要搜索多种类型,则可能需要对docs:查询detailed here使用more_like_this语法。这类似于multi-get APIdocs语法允许您为要分析的每个文档指定index:type:,从而避免Elasticsearch的歧义。
  • curl -XGET 'http://asdf:9200/search_development/_search' -d '{ "query": {"more_like_this": {"fields": ["title","description"], "docs": [{"_index": "search_development", "_type": "my_type", "_id": "1" }}}'
    警告我实际上尚未执行此操作,因此不确定,但是我怀疑这样可以解决此问题。

    关于ruby-on-rails - Elasticsearch more_like_this查询异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25305083/

    相关文章:

    javascript - 'rake assets:precompile' 的时间性能差

    rest - HTTP POST 的 cURL 请求在语法上不正确

    PHP cURL 获取文件,在 Javascript 中使用

    PHP cURL POST 返回 415 - 不支持的媒体类型

    indexing - 子文档是否必须在其 parent 进入Elasticsearch之后进行索引?

    ruby-on-rails - 覆盖 postgresql 数据库

    ruby-on-rails - 将一个对象的多个值赋给另一个对象

    elasticsearch - 如何使用 Java API 使用 Elasticsearch FunctionScore 查询

    java - 如何获取索引别名的映射

    ruby-on-rails - Rails 中名为 "Type"的模型