我目前有以下 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;
}
表示此 POJO 的 JSON 如下。
{
"id" : "someId",
"tags" : [ "one", "two", "three" ]
}
我想要的是定义该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
}
}
}
}
但是,这意味着我将不得不修改我的 POJO 和 JSON 表示。
{
"id": "someId",
"tags": {
"input": [ "one", "two", "three" ]
}
}
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" ]
}
}
最后,我在http://docs.spring.io/spring-data/elasticsearch/docs/current/api/index.html?org/springframework/data/elasticsearch/core/找到了 spring-data-elasticsearch 的这个 javadoc 页面完成/完成.html。我确信这门课有关系,Completion Suggesters
但我不知道如何使用它。
有什么方法可以只使用 Spring 注释来定义 Elasticsearch 映射Completion Suggester
吗?