gpt4 book ai didi

java - 在 Elasticsearch 中查找术语的出现

转载 作者:行者123 更新时间:2023-12-02 23:57:23 28 4
gpt4 key购买 nike

I am using elastic search for autosuggest in JAVA and need to store the terms and their occurences in the index.While indexing products , a particular string can be indexed multiple times.To avoid that , in case it is already stored we have to update occurence of the indexed term. ELastic Search 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;
}

}

Completion object


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

Sample object in elastic search


  {
"_index" : "autosuggest",
"_type" : "autosuggest",
"_id" : "BUj0zGUBr5AQqSH41l0m",
"_score" : 1.0,
"_source" : {
"completion" : {
"input" : [
"Casual Shirts for Men"
],
"weight" : 2
},
"occurence" : 1
}
}

How can I update the occurence if the term is already indexed in elastic search?

最佳答案

由于无法发表评论,因此请将其发布为答案。

@Priancy:您使用的查询似乎不正确。请在下面找到正确的查询。我已经使用问题中提供的示例对象测试了此查询。

"query": {
"match": {
"completion.input": "Casual Shirts for Men"
}
}

还请浏览 this链接,了解如何跳过此方法并增加事件的发生。

谢谢

关于java - 在 Elasticsearch 中查找术语的出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52292554/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com