Best approach to Join two different Elastic Indexes

Hello everyone, I have two Indexes, let me call them Index1 and Index2.

I'm trying to update documents of Index2 that contains an expecif field value.

Basically, for every document in Index1 I get a field value and query this expecif value on Index2, for every document on Index2 that is queried, I copy all fields of index1 document into the relative Index2 document.

I have around 100 fields that I need to copy, what's the best approach?

Here's what I've start thinking:

       SearchResponse scrollResp = client.prepareSearch("ensinosuperiories")
				.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC).setScroll(new TimeValue(60000)).setSize(100)
				.get();
		do {
			for (SearchHit hit : scrollResp.getHits().getHits()) {
				source = hit.getSourceAsMap();
				try {
					institution_cod = source.get("CO_IES").toString();
					institution_name = source.get("NO_IES").toString();
					String[] keys = source.entrySet().toString().split(",");

					UpdateByQueryRequestBuilder updateByQuery = new UpdateByQueryRequestBuilder(client,
							UpdateByQueryAction.INSTANCE);
					updateByQuery.source("ensino_curso").filter(QueryBuilders.termQuery("CO_IES", institution_cod))
							.size(1000).script(new Script(ScriptType.INLINE,
									"ctx._source.NO_IES = "+institution_name,
								"painless", 
									Collections.emptyMap()));
					BulkByScrollResponse response = updateByQuery.get();

				} catch (NullPointerException e) {
				}
			}
			scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000)).execute()
					.actionGet();
		} while (scrollResp.getHits().getHits().length != 0);
	}

Is there a way to copy the fields that doesn't require manual writting every single field?

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