# Join like operation java

**URL:** <https://discuss.elastic.co/t/join-like-operation-java/225717>\
**Category:** Elasticsearch\
**Created:** [March 30, 2020, 5:12pm UTC](https://discuss.elastic.co/t/join-like-operation-java/225717 "2020-03-30T17:12:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohit.singh3](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@rohit.singh3](https://discuss.elastic.co/u/rohit.singh3)\
**Post date:** [March 30, 2020, 5:12pm UTC](https://discuss.elastic.co/t/join-like-operation-java/225717/1 "2020-03-30T17:12:43Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 3, 2020, 4:02pm UTC](https://discuss.elastic.co/t/join-like-operation-java/225717/2 "2020-04-03T16:02:31Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 1, 2020, 4:02pm UTC](https://discuss.elastic.co/t/join-like-operation-java/225717/3 "2020-05-01T16:02:42Z")

</div>

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