Join like operation java

i have two indices employee and organisation, both are linked via a common attribute organisationId. i want to do a search where searchString will be matched with EmpName, EmpDesignation and organisationName, and search should return me the employee object.

Ex:

  • searchString "james", result should return the employee object from employee index having name as james.
  • searchString "developer", result should return the employee objects from employee index who are developer.
  • searchString "microsoft", result should return the organisationId of microsoft from organisation index which will be used to search all employee objects from employee index who belong to microsoft.(Here i need a join like operation).

CODE:

SearchRequest searchRequest = new SearchRequest("indexA","indexB");

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Map<String,Float> fields = new HashMap<String, Float>();
fields.put("column1_From_IndexA", 0.0F);
fields.put("column2_From_IndexA", 0.0F);
fields.put("column1_From_IndexB", 0.0F);

QueryStringQueryBuilder builder = QueryBuilders.queryStringQuery("searchString").fields(fields);
searchSourceBuilder.query(builder);

searchRequest.source(searchSourceBuilder);

SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);

this code snippet return the combination of everything which is messy.

please suggest how to achieve this.
Thanks in advance.

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Please do it with a pure Kibana script and not with Java code as it would be harder to reproduce.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.