Search in sources :

Example 6 with Document

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

the class DocumentUnitTests method shouldParseDocumentFromJson.

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

Example 7 with Document

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

the class DocumentUnitTests method shouldReturnContainsKey.

// DATAES-628
@Test
public void shouldReturnContainsKey() {
    Document document = Document.create().append("string", "value").append("bool", true).append("int", 43).append("long", 42L);
    assertThat(document.containsKey("string")).isTrue();
    assertThat(document.containsKey("not-set")).isFalse();
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 8 with Document

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

the class DocumentUnitTests method shouldRenderDocumentToJson.

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

Example 9 with Document

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

the class DocumentUnitTests method shouldReturnTypedValueLong.

// DATAES-628
@Test
public void shouldReturnTypedValueLong() {
    Document document = Document.create().append("string", "value").append("bool", true).append("int", 43).append("long", 42L);
    assertThat(document.getLong("long")).isEqualTo(42);
    assertThat(document.getLongOrDefault("not-set", 44)).isEqualTo(44);
    assertThat(document.getLongOrDefault("not-set", () -> 44)).isEqualTo(44);
    assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> document.getString("long"));
    assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> document.get("long", String.class));
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 10 with Document

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

the class ResponseConverter method toAliasData.

public static AliasData toAliasData(AliasMetadata aliasMetaData) {
    Document filter = null;
    CompressedXContent aliasMetaDataFilter = aliasMetaData.getFilter();
    if (aliasMetaDataFilter != null) {
        filter = Document.parse(aliasMetaDataFilter.string());
    }
    return AliasData.of(aliasMetaData.alias(), filter, aliasMetaData.indexRouting(), aliasMetaData.getSearchRouting(), aliasMetaData.writeIndex(), aliasMetaData.isHidden());
}
Also used : CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Document(org.springframework.data.elasticsearch.core.document.Document)

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