[英]Is it possible to use Spring's annotations to define Completion Suggester for a mapping in Elasticsearch?
I currently have the following POJO. 我目前有以下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;
}
A JSON that represents this POJO is as follows. 表示此POJO的JSON如下所示。
{
"id" : "someId",
"tags" : [ "one", "two", "three" ]
}
What I want is to define the mapping for the tags
field so that I can use the values in an auto-complete search box. 我想要的是定义tags
字段的映射,以便我可以在自动完成搜索框中使用这些值。 This is supported by Elasticsearch's Completion Suggester. 这得到了Elasticsearch的Completion Suggester的支持。 The documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html seem to suggest to me that I have to set up the mapping as follows. 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
}
}
}
}
However, that would mean that I would have to revise my POJO and JSON representation. 但是,这意味着我必须修改我的POJO和JSON表示。
{
"id": "someId",
"tags": {
"input": [ "one", "two", "three" ]
}
}
I found another good page talking about Completions Suggesters
here http://blog.qbox.io/quick-and-dirty-autocomplete-with-elasticsearch-completion-suggest . 我在http://blog.qbox.io/quick-and-dirty-autocomplete-with-elasticsearch-completion-suggest找到了另一个关于Completions Suggesters
好页面。 However, that page seem to suggest redundancy with the tags
. 但是,该页面似乎建议使用tags
进行冗余。
{
"id": "someId",
"tags": [ "one", "two", "three" ],
"tags_suggest": {
"input": [ "one", "two", "three" ]
}
}
Lastly, I found this javadoc page from spring-data-elasticsearch at http://docs.spring.io/spring-data/elasticsearch/docs/current/api/index.html?org/springframework/data/elasticsearch/core/completion/Completion.html . 最后,我在http://docs.spring.io/spring-data/elasticsearch/docs/current/api/index.html?org/springframework/data/elasticsearch/core/的 spring-data-elasticsearch中找到了这个javadoc页面。 完成/ Completion.html 。 I am sure this class has something to do with Completion Suggesters
but I don't know how to use it. 我确信这个课程与Completion Suggesters
但我不知道如何使用它。
Is there any way I can just use Spring annotations to define the Elasticsearch mapping for Completion Suggester
? 有什么方法可以使用Spring注释来为Completion Suggester
定义Elasticsearch映射吗?
Absolutely yes.. 绝对没错..
you can configure your entity like this: 您可以像这样配置您的实体:
...
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;
...
}
I am not experienced with that, but maybe this annotation can be helpful for you: 我没有这方面的经验,但也许这个注释可能对你有所帮助:
Link to Spring Data Elasticsearch documentation 链接到Spring Data Elasticsearch文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.