是否可以使用Spring的注释为Elasticsearch中的映射定义Completion Suggester?

Jan*_*yne 3 java spring elasticsearch spring-data-elasticsearch elasticsearch-mapping

我目前有以下POJO.

@Document(indexName="ws",type="vid")
public class Vid {
    @Id 
    private String id;

    @Field(type=FieldType.String, index=FieldIndex.not_analyzed)
    private List<String> tags;
}
Run Code Online (Sandbox Code Playgroud)

表示此POJO的JSON如下所示.

{ 
    "id" : "someId",
    "tags" : [ "one", "two", "three" ]
}
Run Code Online (Sandbox Code Playgroud)

我想要的是定义tags字段的映射,以便我可以在自动完成搜索框中使用这些值.这得到了Elasticsearch的Completion Suggester的支持.https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html上的文档似乎向我建议我必须按如下方式设置映射.

{
    "vid": {
        "properties": {
            "id": {
                "type": "string"
            },
            "tags": {
                "type": "completion",
                "index_analyzer": "simple",
                "search_analyzer": "simple",
                "payloads": true
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,这意味着我必须修改我的POJO和JSON表示.

{
    "id": "someId",
    "tags": {
        "input": [ "one", "two", "three" ]
    }
}
Run Code Online (Sandbox Code Playgroud)

我在Completions Suggesters这里找到了另一个好的页面http://blog.qbox.io/quick-and-dirty-autocomplete-with-elasticsearch-completion-suggest.但是,该页面似乎表明了冗余tags.

{
    "id": "someId",
    "tags": [ "one", "two", "three" ],
    "tags_suggest": {
        "input": [ "one", "two", "three" ]
    }
}
Run Code Online (Sandbox Code Playgroud)

最后,我在http://docs.spring.io/spring-data/elasticsearch/docs/current/api/index.html?org/springframework/data/elasticsearch/core/的 spring-data-elasticsearch中找到了这个javadoc页面.完成/ Completion.html.我确信这个课程有一些关系,Completion Suggesters但我不知道如何使用它.

有什么方法可以使用Spring注释来定义Elasticsearch映射Completion Suggester吗?

Efr*_*ama 5

绝对没错..

您可以像这样配置您的实体:

...
import org.springframework.data.elasticsearch.core.completion.Completion;
...

@Document(indexName = "test-completion-index", type = "annotated-completion-type", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
public class YoutEntity {

    @Id
    private String id;
    private String name;

    @CompletionField(payloads = true, maxInputLength = 100)
    private Completion suggest;

    ...
}
Run Code Online (Sandbox Code Playgroud)

例如,检查此链接.