elasticsearch - 如何为索引中的文档设置选择属性
问题描述
如何为索引中的文档设置选择属性,例如使用 spring-data-elasticsearchupdate foo_index set attr1=<attr1_value> where id=<document.id>
解决方案
@Test
public void shouldDoPartialUpdateForExistingDocument() {
// given
String documentId = nextIdAsString();
String messageBeforeUpdate = "some test message";
String messageAfterUpdate = "test message";
SampleEntity sampleEntity = SampleEntity.builder().id(documentId).message(messageBeforeUpdate)
.version(System.currentTimeMillis()).build();
IndexQuery indexQuery = getIndexQuery(sampleEntity);
operations.index(indexQuery, index);
indexOperations.refresh();
org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document
.create();
document.put("message", messageAfterUpdate);
UpdateQuery updateQuery = UpdateQuery.builder(documentId)//
.withDocument(document) //
.build();
// when
operations.update(updateQuery, index);
// then
SampleEntity indexedEntity = operations.get(documentId, SampleEntity.class, index);
assertThat(indexedEntity.getMessage()).isEqualTo(messageAfterUpdate);
}
推荐阅读
- c# - Itext c# - 将 html 转换为 pdf/a 时出错 [xobjects 中不允许使用 smask 键]
- authentication - 缺少 ADFS EnableIdpInitiatedSignonpage 属性
- javascript - 在 JS 类中调用 Setter 的问题
- c++ - 删除重复链表
- raspberry-pi - wxPython 窗口在 RPi 上随机冻结,然后行为怪异
- r - 如何在 R 中使用“内部”时仅过滤特定信息
- postman - 在 Postman 中为导入的集合设置授权
- c# - 如果作为 docker 映像运行,则找不到证书,而作为 IISExpress 运行时返回证书
- python - 如何将 Pydantic BaseModels 列表转换为 Pandas Dataframe
- react-native - 意外的令牌,应为“;” 开玩笑+酶反应原生