Search in sources :

Example 26 with Document

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

the class MappingElasticsearchConverterUnitTests method shouldWriteLocalDate.

// DATAES-716
@Test
void shouldWriteLocalDate() throws JSONException {
    Person person = new Person();
    person.setId("4711");
    person.setFirstName("John");
    person.setLastName("Doe");
    person.birthDate = LocalDate.of(2000, 8, 22);
    person.gender = Gender.MAN;
    String expected = // 
    '{' + // 
    "  \"id\": \"4711\"," + // 
    "  \"first-name\": \"John\"," + // 
    "  \"last-name\": \"Doe\"," + // 
    "  \"birth-date\": \"22.08.2000\"," + // 
    "  \"gender\": \"MAN\"" + '}';
    Document document = Document.create();
    mappingElasticsearchConverter.write(person, document);
    String json = document.toJson();
    assertEquals(expected, json, false);
}
Also used : GeoJsonLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonLineString) GeoJsonMultiLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString) Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 27 with Document

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

the class MappingElasticsearchConverterUnitTests method writeEntityWithMapDataType.

// DATAES-763
@Test
void writeEntityWithMapDataType() {
    Notification notification = new Notification();
    notification.setFromEmail("from@email.com");
    notification.setToEmail("to@email.com");
    Map<String, Object> data = new HashMap<>();
    data.put("documentType", "abc");
    data.put("content", null);
    notification.params = data;
    notification.id = 1L;
    Document document = Document.create();
    mappingElasticsearchConverter.write(notification, document);
    assertThat(document).isEqualTo(notificationAsMap);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GeoJsonLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonLineString) GeoJsonMultiLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString) Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 28 with Document

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

the class MappingElasticsearchConverterUnitTests method readGenericListWithMaps.

// DATAES-797
@Test
void readGenericListWithMaps() {
    Map<String, Object> simpleMap = new HashMap<>();
    simpleMap.put("int", 1);
    List<Map<String, Object>> listWithSimpleMap = new ArrayList<>();
    listWithSimpleMap.add(simpleMap);
    Map<String, List<Map<String, Object>>> mapWithSimpleList = new HashMap<>();
    mapWithSimpleList.put("someKey", listWithSimpleMap);
    Document document = Document.create();
    document.put("schemaLessObject", mapWithSimpleList);
    SchemaLessObjectWrapper wrapper = mappingElasticsearchConverter.read(SchemaLessObjectWrapper.class, document);
    assertThat(wrapper.getSchemaLessObject()).isEqualTo(mapWithSimpleList);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) GeoJsonLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonLineString) GeoJsonMultiLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString) Document(org.springframework.data.elasticsearch.core.document.Document) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 29 with Document

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

the class MappingElasticsearchConverterUnitTests method shouldWriteCollectionsWithNullValues.

// DATAES-845
@Test
void shouldWriteCollectionsWithNullValues() throws JSONException {
    EntityWithListProperty entity = new EntityWithListProperty();
    entity.setId("42");
    entity.setValues(Arrays.asList(null, "two", null, "four"));
    String expected = // 
    '{' + // 
    "  \"id\": \"42\"," + // 
    "  \"values\": [null, \"two\", null, \"four\"]" + '}';
    Document document = Document.create();
    mappingElasticsearchConverter.write(entity, document);
    String json = document.toJson();
    assertEquals(expected, json, false);
}
Also used : GeoJsonLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonLineString) GeoJsonMultiLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString) Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 30 with Document

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

the class ElasticsearchTemplateTests method shouldReturnSourceWhenRequested.

// DATAES-693
@Test
public void shouldReturnSourceWhenRequested() {
    // given
    Map<String, Object> doc = new HashMap<>();
    doc.put("id", "1");
    doc.put("message", "test");
    org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document.from(doc);
    UpdateQuery updateQuery = // 
    UpdateQuery.builder("1").withDocument(// 
    document).withFetchSource(// 
    true).build();
    // when
    UpdateRequest request = getRequestFactory().updateRequest(updateQuery, IndexCoordinates.of("index"));
    // then
    assertThat(request).isNotNull();
    assertThat(request.fetchSource()).isEqualTo(FetchSourceContext.FETCH_SOURCE);
}
Also used : HashMap(java.util.HashMap) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) Object(java.lang.Object) Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

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