为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕哥6287543 2021-09-15 15:05:06
我在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    }  }如果该术语已在弹性搜索中编入索引,我该如何更新出现?
查看完整描述

2 回答

?
慕森王

TA贡献1777条经验 获得超3个赞

这有效:


  "query": {

     "match": {

         "completion": "Casual Shirts for Men"

      }

  }


查看完整回答
反对 回复 2021-09-15
?
千巷猫影

TA贡献1829条经验 获得超7个赞

将此作为答案发布,因为我无法发表评论。


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


"query": {

    "match": {

      "completion.input": "Casual Shirts for Men"

    }

}

还请通过此链接了解如何跳过此方法并增加发生次数。


谢谢


查看完整回答
反对 回复 2021-09-15
  • 2 回答
  • 0 关注
  • 165 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信