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

时间:2019-06-12 17:20:25

标签: elasticsearch hibernate-search nhibernate-search

使用Hibernate Search 5.9和Elastic Server 5.6.10。

我正在尝试使用@Transient注释将3个字段中的数据持久化为单个字段。但是,尽管字段显示在索引结构中,但是当我使用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"
            }
          ]
        }
      }
    ]
  }
}

期望临时字段包含创建索引时试图保留的数据。 我也相信一旦该字段具有数据,如果其引用的字段被更新,它也会更新吗?

1 个答案:

答案 0 :(得分:0)

您在对象字段上添加了@Field注释,该字段显然总是空的。因此,休眠搜索将始终为空字符串编制索引。

对于临时方法,您不需要对象字段。试试这个:

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