What I'm trying to achieve here is to search for two fields in an index. The structure looks like this in kibana :
POST arempris/emptagnames
{
"mappings" : {
"emptags":{
"properties": {
"employeeid": {
"type":"integer"
},
"tagName": {
"type": "text",
"fielddata": true,
"analyzer": "english"
}
}
}
}
}
In java, I had written a code to search for the single field named "tagName" and return the searchHits in jsonArrayBuilder format.
Similarly to this, in this case, is it possible to search employeeid first and then return the list of tagNames associated to that employeeid?
In case of RDBMS, my query would look like : SELECT tagNames from filemetadata where employeeid = 124 and tagName like %slip% and this is what I'm looking to implement using QueryBuilder. Is it possible to implement?
The java code to search for a single field in the index what I've written is :
Client esclient = getClient();
String index = "arempris";
String type = "tags";
QueryBuilder query = QueryBuilders.matchPhrasePrefixQuery("tagName", tagName);
SearchResponse response = esclient.prepareSearch(index).setTypes(type)
.setQuery(query)
.execute().actionGet();
hits = response.getHits().getHits();
System.out.println(hits.length);
for (int i = 0; i < hits.length; i++) {
System.out.println(hits[i].getSourceAsString());
}
Would greatly appreciate your help and thanks in advance.