简体   繁体   English

在弹性搜索中查找术语的出现

[英]Find occurence of a term in elastic search

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. 我正在使用JAVA中的 autosuggest进行弹性搜索 ,需要将术语及其出现的位置存储在索引中。虽然为索引产品建立了索引,但是可以对一个特定的字符串进行多次索引。索引项的 ELastic Search POJO: 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;
}

}

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? 如果该词已在弹性搜索中被索引,如何更新该词的出现?

Posting this as an answer since I can't post a comment. 由于无法发表评论,因此请将其发布为答案。

@Priancy: The query you have used seems to be incorrect. @Priancy:您使用的查询似乎不正确。 Please find the correct query below. 请在下面找到正确的查询。 I have tested this query with the sample object you have provided in the question. 我已经使用您在问题中提供的示例对象测试了此查询。

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

Please also go through this link on how you can skip this approach and increment the occurrence. 还请通过链接了解如何跳过此方法并增加发生次数。

Thanks 谢谢

This works: 这有效:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM