Select 从 lucene 的 BoolQueryBuilder 中的索引连接 3 个字段后的字符串

Select a strings after concatenating 3 fields from index in lucene's BoolQueryBuilder

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

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

Database column: Data
a. address: 123, a street, city, state
   Fillr1 : 000
   Fillr2: 0
   Fillr3: 358

b. address: 234, a street, city, state
   Fillr1 : 000
   Fillr2: 0
   Fillr3: 258

b. address: 567, a street, city, state
   Fillr1 : 000
   Fillr2: 0
   Fillr3: 005

我想 concatenate/or 可能不是,并将三个字段 Fillr1 + Fillr2 + Fillr3 与从前端应用程序接收的输入数组进行比较。假设输入数组包含的数据为:

[0000004, 0000005, 0000258, 0000358, 0035648]

我只想select包含与输入数组项匹配的数据的行。

到目前为止,我已经尝试过过滤器,must/should 查询以及主要的 select 数据,下面是我尝试过的最新版本的代码。这适用于输入数组包含弹性服务器上的数据的情况,但是如果我删除一条包含弹性服务器上数据的记录,但输入数组下不存在相同的记录,那么结果集也包含与已删除记录。

agent number e.g. 0000258

 BoolQueryBuilder matchQueryBuilder = QueryBuilders.boolQuery();
                     matchQueryBuilder.must(QueryBuilders.matchQuery("cltseqnum", clt0300to.getCltseqnum()));
                     matchQueryBuilder.must(QueryBuilders.matchQuery("addrseqnum", clt0300to.getAddrseqnum()));



                     if(!allAgentsAssignedFlag){
                         BoolQueryBuilder secondQuery;
                         for(String agentNum : allUserAgenciesList) {//allUserAgenciesList -> [0000004, 0000005, 0000258, 0000358, 0035648]
                             secondQuery = QueryBuilders.boolQuery();

                             secondQuery.must(QueryBuilders.matchQuery("policies.fillr1",agentNum.substring(0, 3)))
                             .must(QueryBuilders.matchQuery("policies.rpt0agt0nr",agentNum.substring(3, 4)))
                             .must(QueryBuilders.matchQuery("policies.fillr2",agentNum.substring(4, 7)));
                             matchQueryBuilder.must(secondQuery);


                         }

                     }

下面是 json 查询的结果:

{
  "bool" : {
    "must" : [
      {
        "match" : {
          "cltseqnum" : {
            "query" : 335,
            "operator" : "OR",
            "prefix_length" : 0,
            "max_expansions" : 50,
            "fuzzy_transpositions" : true,
            "lenient" : false,
            "zero_terms_query" : "NONE",
            "boost" : 1.0
          }
        }
      },
      {
        "match" : {
          "addrseqnum" : {
            "query" : 1,
            "operator" : "OR",
            "prefix_length" : 0,
            "max_expansions" : 50,
            "fuzzy_transpositions" : true,
            "lenient" : false,
            "zero_terms_query" : "NONE",
            "boost" : 1.0
          }
        }
      }
    ],
    "should" : [
      {
        "bool" : {
          "must" : [
            {
              "match" : {
                "policies.fillr1" : {
                  "query" : "000",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            },
            {
              "match" : {
                "policies.rpt0agt0nr" : {
                  "query" : "0",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            },
            {
              "match" : {
                "policies.fillr2" : {
                  "query" : "004",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            }
          ],
          "disable_coord" : false,
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      },
      {
        "bool" : {
          "must" : [
            {
              "match" : {
                "policies.fillr1" : {
                  "query" : "000",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            },
            {
              "match" : {
                "policies.rpt0agt0nr" : {
                  "query" : "0",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            },
            {
              "match" : {
                "policies.fillr2" : {
                  "query" : "005",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            }
          ],
          "disable_coord" : false,
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      },
      {
        "bool" : {
          "must" : [
            {
              "match" : {
                "policies.fillr1" : {
                  "query" : "000",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            },
            {
              "match" : {
                "policies.rpt0agt0nr" : {
                  "query" : "0",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            },
            {
              "match" : {
                "policies.fillr2" : {
                  "query" : "258",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            }
          ],
          "disable_coord" : false,
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      },
      {
        "bool" : {
          "must" : [
            {
              "match" : {
                "policies.fillr1" : {
                  "query" : "000",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            },
            {
              "match" : {
                "policies.rpt0agt0nr" : {
                  "query" : "0",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            },
            {
              "match" : {
                "policies.fillr2" : {
                  "query" : "358",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            }
          ],
          "disable_coord" : false,
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      },
      {
        "bool" : {
          "must" : [
            {
              "match" : {
                "policies.fillr1" : {
                  "query" : "003",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            },
            {
              "match" : {
                "policies.rpt0agt0nr" : {
                  "query" : "5",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            },
            {
              "match" : {
                "policies.fillr2" : {
                  "query" : "648",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : true,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            }
          ],
          "disable_coord" : false,
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      }
    ],
    "disable_coord" : false,
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}

解决了这个问题,在新自定义字段(在数据库端不可用)的 getter 方法上使用了 @Transient 注释,并将我的数据连接到它。更多详情,请关注下方link :