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

我在JAVA 中对 autosuggest使用弹性搜索,需要在索引中存储术语及其出现。虽然索引产品,可以多次索引特定字符串。为了避免这种情况,如果它已经存储,我们必须更新出现索引项。弹性搜索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

    }

  }

如果该术语已在弹性搜索中编入索引,我该如何更新出现?


慕哥6287543
浏览 166回答 2
2回答

慕森王

这有效:&nbsp; "query": {&nbsp; &nbsp; &nbsp;"match": {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"completion": "Casual Shirts for Men"&nbsp; &nbsp; &nbsp; }&nbsp; }

千巷猫影

将此作为答案发布,因为我无法发表评论。@Priancy:您使用的查询似乎不正确。请在下面找到正确的查询。我已使用您在问题中提供的示例对象测试了此查询。"query": {&nbsp; &nbsp; "match": {&nbsp; &nbsp; &nbsp; "completion.input": "Casual Shirts for Men"&nbsp; &nbsp; }}还请通过此链接了解如何跳过此方法并增加发生次数。谢谢
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java