繁体   English   中英

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

[英]Is it possible to use Spring's annotations to define Completion Suggester for a mapping in Elasticsearch?

我目前有以下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" ]
    }
}

我在http://blog.qbox.io/quick-and-dirty-autocomplete-with-elasticsearch-completion-suggest找到了另一个关于Completions Suggesters好页面。 但是,该页面似乎建议使用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页面。 完成/ Completion.html 我确信这个课程与Completion Suggesters但我不知道如何使用它。

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

绝对没错..

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

...
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;

    ...
}

例如,检查此链接

我没有这方面的经验,但也许这个注释可能对你有所帮助:
链接到Spring Data Elasticsearch文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM