| | |
| | | import org.elasticsearch.client.indices.GetIndexRequest; |
| | | import org.elasticsearch.index.query.BoolQueryBuilder; |
| | | import org.elasticsearch.index.query.QueryBuilders; |
| | | import org.elasticsearch.index.reindex.*; |
| | | import org.elasticsearch.index.reindex.BulkByScrollResponse; |
| | | import org.elasticsearch.index.reindex.DeleteByQueryRequest; |
| | | import org.elasticsearch.index.reindex.UpdateByQueryRequest; |
| | | import org.elasticsearch.script.Script; |
| | | import org.elasticsearch.script.ScriptType; |
| | | import org.elasticsearch.search.SearchHit; |
| | | import org.elasticsearch.search.SearchHits; |
| | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.elasticsearch.script.Script; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | |
| | | // 刷新索引,确保文档可搜索 |
| | | client.indices().refresh(new RefreshRequest(esParam.getIndexName()), RequestOptions.DEFAULT); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | System.out.println("批量插入结果: " + !bulkResponse.hasFailures()); |
| | | // System.out.println("批量插入结果: " + !bulkResponse.hasFailures()); |
| | | } |
| | | } |
| | | // 返回 |
| | |
| | | // 刷新索引,确保文档可搜索 |
| | | client.indices().refresh(new RefreshRequest(esParam.getIndexName()), RequestOptions.DEFAULT); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | System.out.println("批量插入结果: " + !bulkResponse.hasFailures()); |
| | | // System.out.println("批量插入结果: " + !bulkResponse.hasFailures()); |
| | | } |
| | | } |
| | | // 返回 |
| | |
| | | "tableId", household.getId().toString(), |
| | | "tableName", "jczz_household", |
| | | "title", household.getName(), |
| | | "relationship", household.getRelationship(), |
| | | "name", household.getName(), |
| | | "phone", household.getPhoneNumber(), |
| | | "idCard", household.getIdCard(), |
| | |
| | | // 刷新索引,确保文档可搜索 |
| | | client.indices().refresh(new RefreshRequest(esParam.getIndexName()), RequestOptions.DEFAULT); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | System.out.println("批量插入结果: " + !bulkResponse.hasFailures()); |
| | | // System.out.println("批量插入结果: " + !bulkResponse.hasFailures()); |
| | | } |
| | | } |
| | | // 返回 |
| | |
| | | // 刷新索引,确保文档可搜索 |
| | | client.indices().refresh(new RefreshRequest(esParam.getIndexName()), RequestOptions.DEFAULT); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | System.out.println("批量插入结果: " + !bulkResponse.hasFailures()); |
| | | // System.out.println("批量插入结果: " + !bulkResponse.hasFailures()); |
| | | } |
| | | } |
| | | // 返回 |
| | |
| | | "articleType", article.getArticleType() |
| | | ); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | |
| | | "communityCode", placeService.getCommunityCode(place.getId()) |
| | | ); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | |
| | | "communityCode", houseService.getCommunityCode(house.getId()) |
| | | ); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | |
| | | @Async |
| | | public void addHousehold(EsParam esParam, HouseholdEntity household) { |
| | | if (elasticsearchSync) { |
| | | // 如果关系为空,则默认为19 |
| | | if (household.getRelationship() == null) { |
| | | household.setRelationship(19); |
| | | } |
| | | try { |
| | | indexDocument(esParam.getIndexName(), |
| | | "tableId", household.getId().toString(), |
| | |
| | | "communityCode", householdService.getCommunityCode(household.getId()) |
| | | ); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | // 输出操作结果 |
| | | boolean acknowledged = deleteResponse.isAcknowledged(); |
| | | System.out.println("索引删除成功: " + acknowledged); |
| | | // System.out.println("索引删除成功: " + acknowledged); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | |
| | | try { |
| | | indexDocument(esParam.getIndexName(), str); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | // 刷新索引,确保文档可搜索 |
| | | client.indices().refresh(new RefreshRequest(esParam.getIndexName()), RequestOptions.DEFAULT); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | |
| | | BulkByScrollResponse bulkResponse = |
| | | client.deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | return true; |