mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-31 09:12:11 +00:00
DATAES-788 - Add missing path mapping to completion context.
Original PR: #424
This commit is contained in:
parent
bbc9ec213a
commit
89944b66c4
@ -1,7 +1,5 @@
|
||||
package org.springframework.data.elasticsearch.annotations;
|
||||
|
||||
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
@ -9,6 +7,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
|
||||
|
||||
/**
|
||||
* Based on reference doc - https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html
|
||||
*
|
||||
@ -26,4 +26,5 @@ public @interface CompletionContext {
|
||||
|
||||
String precision() default "";
|
||||
|
||||
String path() default "";
|
||||
}
|
||||
|
@ -81,6 +81,7 @@ public class MappingBuilder {
|
||||
private static final String FIELD_PARENT = "_parent";
|
||||
private static final String FIELD_CONTEXT_NAME = "name";
|
||||
private static final String FIELD_CONTEXT_TYPE = "type";
|
||||
private static final String FIELD_CONTEXT_PATH = "path";
|
||||
private static final String FIELD_CONTEXT_PRECISION = "precision";
|
||||
private static final String FIELD_DYNAMIC_TEMPLATES = "dynamic_templates";
|
||||
|
||||
@ -279,9 +280,15 @@ public class MappingBuilder {
|
||||
builder.startObject();
|
||||
builder.field(FIELD_CONTEXT_NAME, context.name());
|
||||
builder.field(FIELD_CONTEXT_TYPE, context.type().name().toLowerCase());
|
||||
|
||||
if (context.precision().length() > 0) {
|
||||
builder.field(FIELD_CONTEXT_PRECISION, context.precision());
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(context.path())) {
|
||||
builder.field(FIELD_CONTEXT_PATH, context.path());
|
||||
}
|
||||
|
||||
builder.endObject();
|
||||
}
|
||||
builder.endArray();
|
||||
|
@ -43,6 +43,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.assertj.core.data.Percentage;
|
||||
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
|
||||
import org.json.JSONException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -560,6 +561,28 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
assertEquals(expected, mapping, true);
|
||||
}
|
||||
|
||||
@Test // DATAES-788
|
||||
void shouldWriteCompletionContextInfo() throws JSONException {
|
||||
String expected = "{\n" + //
|
||||
" \"properties\": {\n" + //
|
||||
" \"suggest\": {\n" + //
|
||||
" \"type\": \"completion\",\n" + //
|
||||
" \"contexts\": [\n" + //
|
||||
" {\n" + //
|
||||
" \"name\": \"location\",\n" + //
|
||||
" \"type\": \"geo\",\n" + //
|
||||
" \"path\": \"proppath\"\n" + //
|
||||
" }\n" + //
|
||||
" ]\n" + //
|
||||
" }\n" + //
|
||||
" }\n" + //
|
||||
"}";
|
||||
|
||||
String mapping = getMappingBuilder().buildPropertyMapping(CompletionDocument.class);
|
||||
|
||||
assertEquals(expected, mapping, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Xiao Yu
|
||||
*/
|
||||
@ -1029,4 +1052,14 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
static class ValueDoc {
|
||||
@Field(type = Text) private ValueObject valueObject;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Document(indexName = "completion")
|
||||
static class CompletionDocument {
|
||||
@Id private String id;
|
||||
|
||||
@CompletionField(contexts = { @CompletionContext(name = "location", type = ContextMapping.Type.GEO,
|
||||
path = "proppath") }) private Completion suggest;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user