【发布时间】:2019-02-16 22:33:53
【问题描述】:
我在 JAVA 中使用 elastic search for autosuggest 并且需要将术语及其出现存储在索引。在索引产品时,可以多次索引特定字符串。为避免这种情况,如果它已经存储,我们必须更新索引词的出现。 弹性搜索 POJO:
@Document(indexName = "autosuggest", type = "autosuggest")
public class Autosuggest {
@Id
@Field(pattern ="id")
private String id;
@Field(pattern ="completion")
private Completion completion;
@Field(pattern ="occurence")
private Integer occurence;
public String getId() {
return id;
}
public Completion getCompletion() {
return completion;
}
public void setCompletion(Completion completion) {
this.completion = completion;
}
public Integer getOccurence() {
return occurence;
}
public void setOccurence(Integer occurence) {
this.occurence = occurence;
}
}
完成对象
public class Completion {
private List<String> input;
private Integer weight;
public List<String> getInput() {
return input;
}
public void setInput(List<String> input) {
this.input = input;
}
public Integer getWeight() {
return weight;
}
public void setWeight(Integer weight) {
this.weight = weight;
}
public Completion(List<String> input, Integer weight) {
super();
this.input = input;
this.weight = weight;
}
}
弹性搜索中的示例对象
{
"_index" : "autosuggest",
"_type" : "autosuggest",
"_id" : "BUj0zGUBr5AQqSH41l0m",
"_score" : 1.0,
"_source" : {
"completion" : {
"input" : [
"Casual Shirts for Men"
],
"weight" : 2
},
"occurence" : 1
}
}
如果术语已在弹性搜索中编入索引,我如何更新出现次数?
【问题讨论】:
-
嗨 Priancy,您可以在索引数据之前对其进行验证。检查它是否在索引中可用。如果是,那么您可以使用递增的出现来更新/替换整个文档。
-
@PKhode 使用了这个查询: curl -X GET "localhost:9200/autosuggest/autosuggest/_search" -H 'Content-Type: application/json' -d' {"size": 0, "query": {"match": { "input": "男士休闲衬衫" }}}' 得到 {"took":0,"timed_out":false,"_shards":{"total":5, “成功”:5,“跳过”:0,“失败”:0},“点击”:{“总”:0,“最大得分”:0.0,“点击”:[]}}。它没有返回确切的文档
标签: java elasticsearch autocomplete autosuggest