尝试在我的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"]}} }'
最佳答案
两个潜在的问题:
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 API。 docs
语法允许您为要分析的每个文档指定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/