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

标签 java elasticsearch autocomplete autosuggest

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/

相关文章:

Java MIDI 音序器延迟

java - Android Studio - 'Cannot resolve symbol' 语法高亮显示错误,尽管构建正常

nginx - kibana 服务未运行

elasticsearch - JVM缓冲池只会增长

java - Places.GeoDataApi.getAutocompletePredictions

android - 从自动完成 TextView 中选择联系人

java - 无法为象限检查程序创建正确的方法

java - 尝试提取对象的参数并将其传递给另一个类(不确定标题)

elasticsearch - Search Guard Kibana clientcert 身份验证

javascript - 滚动菜单时,JQuery UI 自动完成在文本框中显示 [Object object]