我在JAVA 中對(duì) autosuggest使用彈性搜索,需要在索引中存儲(chǔ)術(shù)語及其出現(xiàn)。雖然索引產(chǎn)品,可以多次索引特定字符串。為了避免這種情況,如果它已經(jīng)存儲(chǔ),我們必須更新出現(xiàn)索引項(xiàng)。彈性搜索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;}}完成對(duì)象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;}}彈性搜索中的示例對(duì)象 { "_index" : "autosuggest", "_type" : "autosuggest", "_id" : "BUj0zGUBr5AQqSH41l0m", "_score" : 1.0, "_source" : { "completion" : { "input" : [ "Casual Shirts for Men" ], "weight" : 2 }, "occurence" : 1 } }如果該術(shù)語已在彈性搜索中編入索引,我該如何更新出現(xiàn)?
2 回答

慕森王
TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊
這有效:
"query": {
"match": {
"completion": "Casual Shirts for Men"
}
}

千巷貓影
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
將此作為答案發(fā)布,因?yàn)槲覠o法發(fā)表評(píng)論。
@Priancy:您使用的查詢似乎不正確。請(qǐng)?jiān)谙旅嬲业秸_的查詢。我已使用您在問題中提供的示例對(duì)象測(cè)試了此查詢。
"query": {
"match": {
"completion.input": "Casual Shirts for Men"
}
}
還請(qǐng)通過此鏈接了解如何跳過此方法并增加發(fā)生次數(shù)。
謝謝
添加回答
舉報(bào)
0/150
提交
取消