[英]Find occurence of a term in elastic search
我正在使用JAVA中的 autosuggest進行彈性搜索 ,需要將術語及其出現的位置存儲在索引中。雖然為索引產品建立了索引,但是可以對一個特定的字符串進行多次索引。索引項的 ELastic搜索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:您使用的查詢似乎不正確。 請在下面找到正確的查詢。 我已經使用您在問題中提供的示例對象測試了此查詢。
"query": {
"match": {
"completion.input": "Casual Shirts for Men"
}
}
還請通過此鏈接了解如何跳過此方法並增加發生次數。
謝謝
這有效:
"query": {
"match": {
"completion": "Casual Shirts for Men"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.