从Lucene的BoolQueryBuilder中的索引连接3个字段后,选择一个字符串 [英] Select a strings after concatenating 3 fields from index in lucene's BoolQueryBuilder

查看:246
本文介绍了从Lucene的BoolQueryBuilder中的索引连接3个字段后,选择一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Hibernate Search 5.9和Elastic Server 5.6.10.

Using Hibernate Search 5.9 and elastic server 5.6.10.

我正在尝试使用@Transient注释将3个字段中的数据持久化为单个字段.但是,尽管这些字段显示在索引结构中,但是当我使用curl/chrome查询索引时却没有显示相同的字段.它不会出现在索引上,并且数据会以这种方式丢失.

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.

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

我要串联/或者可能不是,并将三个字段Fillr1 + Fillr2 + Fillr3与从前端应用程序接收到的输入数组进行比较.假设输入数组包含如下数据:

I want to concatenate/or may be not and compare three fields Fillr1 + Fillr2 + Fillr3 to an array of input received from front end application. Lets assume the input array contains data as:

[0000004, 0000005, 0000258, 0000358, 0035648]

我只想选择包含与输入数组项匹配的数据的行.

I just want to select the row which contains data matching to the input array items.

到目前为止,我已经尝试过过滤器,必须/应该查询以及主要的选择数据,以下是我尝试过的最新版本的代码.这适用于以下情况:输入数组包含弹性服务器上的数据,但是如果我删除了一条包含弹性服务器上的数据的记录,但在输入数组下不存在该记录,则结果集也包含与该数组有关的数据.删除的记录.

Till now I've tried filters, must/should queries along with the main select data, below is the latest version of code, I tried. This works for scenario when the input array contains data which is on the elastic server, but If I remove one record which contains data on elastic server, but the same is not present under the input array then also the result set contains data pertaining to the removed record.

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查询:

Below is the resulted json query:

{
  "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方法(数据库侧不可用)的getter方法上使用了@Transient注释,并连接了我的数据做到这一点.有关更多详细信息,请点击以下链接:

Got a work around for this, used @Transient annotation on getter method of a new custom field(which is not available on the database side) and concatenated my data to it. For more details, please follow below link :

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

这篇关于从Lucene的BoolQueryBuilder中的索引连接3个字段后,选择一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆