I've got an in-memory instance of elastic search running, and doing some exploratory coding to learn the search java API. I am able to submit documents to the index and retrieve them using GET, but when I try a simple search query, I am not getting any results.
// first, try a get request, to make sure there is something in the index
GetResponse results = client.prepareGet(INDEX_NAME, INDEX_TYPE, testID)
.execute()
.actionGet();
// this assertion succeeds, as we expect it to.
assertThat(results.getId()).isEqualTo(testID);
// next, try the simplest possible search
SearchResponse s1 = client.prepareSearch(INDEX_NAME).setQuery(matchAllQuery())
.execute()
.actionGet();
// this assertion fails. why? answer: when we have an in-memory node, we have to
// manually call refresh on the indexing, after submitting a document.
assertThat(s1.getHits().totalHits()).isGreaterThanOrEqualTo(1);
after some testing, I think the problem is in how I am setting up my Node and associated client (in memory):
@BeforeMethod
public void setup() {
// set up elastic search to run locally. since the transaction
// log needs a filesystem, we can't run it as purely in memory,
// but we can set the data directories into "target", so that maven will
// clean up after the fact: http://bit.ly/OTN7Qf
Settings settings = ImmutableSettings.settingsBuilder()
.put("node.http.enabled", true)
.put("path.logs","target/elasticsearch/logs")
.put("path.data","target/elasticsearch/data")
.put("gateway.type", "none")
.put("index.store.type", "memory")
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 1).build();
node = NodeBuilder.nodeBuilder().local(true).settings(settings).node();
client = node.client();
}
By default, you cannot use from and size to page through more than 10,000 hits. This limit is a safeguard set by the index. max_result_window index setting. If you need to page through more than 10,000 hits, use the search_after parameter instead.
You can use the search API to search and aggregate data stored in Elasticsearch data streams or indices. The API's query request body parameter accepts queries written in Query DSL. The following request searches my-index-000001 using a match query. This query matches documents with a user.id value of kimchy .
You can use cURL in a UNIX terminal or Windows command prompt, the Kibana Console UI, or any one of the various low-level clients available to make an API call to get all of the documents in an Elasticsearch index. All of these methods use a variation of the GET request to search the index.
Someone on the elastic search google group was kind enough to help me out here. After submitting a document to an in-memory node, I need to refresh the index:
node.client().admin().indices().prepareRefresh().execute().actionGet();
calling refresh fixed the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With