Search in sources :

Example 56 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class DocumentUnitTests method shouldCreateNewDocumentFromMap.

// DATAES-628
@Test
public void shouldCreateNewDocumentFromMap() {
    Document document = Document.from(Collections.singletonMap("key", "value"));
    assertThat(document).containsEntry("key", "value");
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 57 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class DocumentUnitTests method shouldRenderToString.

// DATAES-628
@Test
public void shouldRenderToString() {
    Document document = Document.from(Collections.singletonMap("key", "value"));
    document.setId("123");
    document.setVersion(42);
    assertThat(document).hasToString("MapDocument@123#42 {\"key\":\"value\"}");
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 58 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project IT-Demo by yanghaiji.

the class EsTempWeb method update.

/**
 * <p>
 * 更新
 * </p>
 *
 * @param
 * @return void
 * @version 1.0.0
 * @author hai ji
 * @since 2022/2/9
 */
@PostMapping
public void update() {
    Document document = Document.create();
    document.put("title", 1214666);
    document.put("price", 66.6);
    UpdateQuery updateQuery = UpdateQuery.builder("164439571754").withDocument(document).build();
    // 单条更新
    UpdateResponse response = elasticsearchTemplate.update(updateQuery, IndexCoordinates.of("sys_user"));
    System.out.println(response.getResult().name());
    // 批量更新
    List<UpdateQuery> list = new LinkedList<>();
    list.add(updateQuery);
    elasticsearchTemplate.bulkUpdate(list, IndexCoordinates.of("sys_user"));
}
Also used : UpdateResponse(org.springframework.data.elasticsearch.core.query.UpdateResponse) UpdateQuery(org.springframework.data.elasticsearch.core.query.UpdateQuery) Document(org.springframework.data.elasticsearch.core.document.Document) LinkedList(java.util.LinkedList)

Aggregations

Document (org.springframework.data.elasticsearch.core.document.Document)58 Test (org.junit.jupiter.api.Test)48 GeoJsonLineString (org.springframework.data.elasticsearch.core.geo.GeoJsonLineString)15 GeoJsonMultiLineString (org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString)15 DisplayName (org.junit.jupiter.api.DisplayName)7 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)5 GetResult (org.elasticsearch.index.get.GetResult)4 SearchDocument (org.springframework.data.elasticsearch.core.document.SearchDocument)4 Object (java.lang.Object)2 GetResponse (org.elasticsearch.action.get.GetResponse)2 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)2 MappingMetadata (org.elasticsearch.cluster.metadata.MappingMetadata)2 BytesArray (org.elasticsearch.common.bytes.BytesArray)2 DocumentField (org.elasticsearch.common.document.DocumentField)2 GeoPoint (org.springframework.data.elasticsearch.core.geo.GeoPoint)2 AliasData (org.springframework.data.elasticsearch.core.index.AliasData)2 Settings (org.springframework.data.elasticsearch.core.index.Settings)2