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

房东的猫 提交于 2019-12-11 15:08:49

问题


Using Hibernate Search 5.9 and elastic server 5.6.10.

I'm trying to persist data from 3 fields into a single field with @Transient annotation. But though the fields shows up in the index structure, the same does not show up when I query the index with curl/chrome. Its not present on the index and the data is lost this way.

Code:

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

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

Result on Index:

{
  "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"
            }
          ]
        }
      }
    ]
  }
}

Expect the transient field to contain the data am trying to persist while creating the index. Also I believe once the field has the data, it will too update if the fields its referencing is updated?


回答1:


You added the @Field annotation on an object field which is, apparently, always empty. Hibernate Search will thus always index an empty string.

You don't need an object field for transient methods. Try this:

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


来源:https://stackoverflow.com/questions/56567435/transient-with-field-annotated-field-not-showing-in-index-on-elastic-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!