I have the following problem: When I execute this command
curl -XGET "localhost:9200/customer/external/_search?pretty" -d @json.txt
Where json.txt looks like this:
{ "query":{ "match":{ "_id":"1" } } }
I get the following output (I shortened it):
{
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "customer",
"_type" : "external",
"_id" : "1",
"_score" : 1.0,
"_source":{
"name":"Jan",
"age":99,
"address":{
"city":"KKKKKKK",
"zip":"xxxx"
}
}
} ]
}
Now I'm trying to do the same using the Java API but I just cannot manage to get it done (I tried like 8 different approches). I get always 0 hits. In the code I now set the source file as a string directly as a source but as you can see I also tried using the XContentBuilder and WrapperQueryBuilder versions but nothing worked. Here's my code:
public void processQuery(String filePath, String index, String... types) {
String source = convertFileToString(filePath);
//XContentBuilder query = null;
//try {
// JSONObject json = new JSONObject(source.trim());
// query = convertJsonToXContentBuilder(json);
//} catch (...) {...}
//WrapperQueryBuilder query = QueryBuilders.wrapperQuery(source);
SearchResponse response = client.prepareSearch(index)
.setSource(source)
// .setQuery(query)
.setTypes(types)
.get();
}
As a response I dont get any hits at all:
{
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
I hope anyone has an idea about this cause I'm already sick of trying to find a solution :/
Best regardes, Jan
{ "query":{ "match":{ "_id":"1" } } }. And I pass as index"customer"and types"external".