带有@Field 注释字段的@Transient 未显示在弹性服务器的索引中

@Transient with @Field annotated field not showing in index on elastic server

使用 Hibernate Search 5.9 和弹性服务器 5.6.10。

我正在尝试将来自 3 个字段的数据保存到带有 @Transient 注释的单个字段中。但是,尽管这些字段显示在索引结构中,但当我使用 curl/chrome 查询索引时,它们并没有显示出来。它不在索引中,数据就这样丢失了。

代码:

@Transient
                @Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
                private String fullAgentNumber = "";

                public String getFullAgentNumber() {
                                return this.fillr1 +""+ this.rpt0agt0nr +""+ this.fillr2;
                }

索引结果:

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "master_policy_index",
        "_type" : "com.csc.pt.svc.data.to.Basclt1400TO",
        "_id" : "00,0004087,WCV,05,00",
        "_score" : 1.0,
        "_source" : {
          "id" : "00,0004087,WCV,05,00",
          "location" : "00",
         "symbol" : "WCV",
          "module" : "00",
          "policy0num" : "0004087",
          "master0co" : "05",
          "cltseqnum" : 277,
          "addrseqnum" : "1",
          "policies" : [
            {
              "location" : "00",
              "symbol" : "WCV",
              "module" : "00",
              "policy0num" : "0004087",
              "master0co" : "05",
              "trans0stat" : "P",
              "id02" : "02",
              "eff0yr" : "118",
              "eff0mo" : "03",
              "eff0da" : "15",
              "exp0yr" : "119",
              "exp0mo" : "03",
              "exp0da" : "15",
              "fillr1" : "000",
              "rpt0agt0nr" : "0",
              "fillr2" : "358",
              "tot0ag0prm" : "0.00",
              "line0bus" : "WCV",
              "issue0code" : "N",
              "type0act" : "NB"
            }
          ]
        }
      }
    ]
  }
}

希望瞬态字段包含创建索引时试图保留的数据。 另外我相信一旦该字段有数据,如果它引用的字段被更新,它也会更新?

您在显然始终为空的对象字段上添加了 @Field 注释。因此,Hibernate Search 将始终索引一个空字符串。

瞬态方法不需要对象字段。试试这个:

@Transient
                @Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
                public String getFullAgentNumber() {
                                return this.fillr1 +""+ this.rpt0agt0nr +""+ this.fillr2;
                }