本文介绍了集成测试弹性搜索,时间问题,文档未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在java中有一个集成测试,其中包括一个执行一些事情的立面,其中包括一个对弹性搜索数据库的索引操作。这个弹性搜索数据库已经非常天真的设置(开箱即用的东西,实际上我在学习中)。
这个插入在这个外观里面完成,java api也是非常天真的,这个例子几乎完全从弹性搜索中复制粘贴,如下所述:。我插入一个带有某种有效载荷的文件,并以相同的方式查找。



如果我在调试中运行并在外观设置断点后才能正常工作,但是如果我没有放置这个断点或者不在调试中运行,它将失败,没有找到结果。这让我觉得我真的做错了事情。此外,应用程序本身也是工作(插入等等),所以我的集成测试可能会出现问题,而不是我的复制代码。



我猜想索引操作返回的索引没有真正完成,或者有一些复制过程在搜索之前还没有完成,或者类似的,但它不知道我究竟是什么,似乎无法解决它。
我没有尝试在一个节点和一个分片上弹性,也许这里有什么问题,但是我真的不知道究竟是什么,所以我没有走这条路。
像我说的那样,刚刚开始使用弹性,所以我可能会错过一些关键和初学者风格的东西。我可以粘贴我的确切的代码,如果需要,但像我说,它归结为使用弹性搜索网站的两个代码片段在测试。



Kasper

解决方案

在索引操作调用后,Elasticsearch不会立即使数据可用。默认情况下等待1秒钟,以便更多数据到达。但是,您可以通过调用刷新立即强制弹性搜索使所有数据可用。

  client.admin()索引()刷新(refreshRequest())actionGet()。; 

在您完成索引后,检查结果之前,尝试添加此操作。


I have an integration test, in java, of a facade that does a few things, among which is an index operation into an elastic search database. This elastic search database has been very naively set up (out of the box stuff actually, I'm in the learning fase). The insertion is done, inside that facade, with the java api, also very naively, with the example nearly completely copy pasted from elastic search, as described here : http://www.elasticsearch.org/guide/reference/java-api/index_.html.

Afterwards I test a whether my facade did its stuff correctly, part of it is checking whether that document has really been inserted in the database. This I do, again, in the way elastic describes on their site : http://www.elasticsearch.org/guide/reference/java-api/search.html. I insert a document with a certain payload and look it up the same way.

This test works if I run in debug and set a breakpoint after facade did it's stuff, but it fails with no results found if I don't put this breakpoint or do not run in debug. This makes me think I'm really doing something wrong. Also, the application itself works (inserts and so on), so there's likely something wrong with my integration test, and not with my copy pasted code.

I guess that after the indexing operation returns the indexing is not really finished yet, or there is some replication going on that doesn't complete before the search, or something like that, but it eludes me what exactly and I can't seem to get it solved either. I didn't try to put elastic on one node and one shard yet, maybe there's something wrong there, but I don't really see what exactly, so I didn't walk that path yet. Like I said, just started using elastic so I might be missing something crucial and beginner-style. I can paste my exact code if needs be, but like I said it boils down to using two code snippets from the elastic search site in a test.

Kasper

解决方案

Elasticsearch doesn't make data available immediately after the index operation is called. It waits for 1 sec by default for more data to arrive. However, you can force elasticsearch to make all data available immediately by calling refresh:

client.admin().indices().refresh(refreshRequest()).actionGet();

Try adding this operation after you facade is done indexing and before you check the result.

这篇关于集成测试弹性搜索,时间问题,文档未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 00:51