<i id='pGnl6'><tr id='pGnl6'><dt id='pGnl6'><q id='pGnl6'><span id='pGnl6'><b id='pGnl6'><form id='pGnl6'><ins id='pGnl6'></ins><ul id='pGnl6'></ul><sub id='pGnl6'></sub></form><legend id='pGnl6'></legend><bdo id='pGnl6'><pre id='pGnl6'><center id='pGnl6'></center></pre></bdo></b><th id='pGnl6'></th></span></q></dt></tr></i><div id='pGnl6'><tfoot id='pGnl6'></tfoot><dl id='pGnl6'><fieldset id='pGnl6'></fieldset></dl></div>
  • <small id='pGnl6'></small><noframes id='pGnl6'>

      1. <tfoot id='pGnl6'></tfoot>
      2. <legend id='pGnl6'><style id='pGnl6'><dir id='pGnl6'><q id='pGnl6'></q></dir></style></legend>

          <bdo id='pGnl6'></bdo><ul id='pGnl6'></ul>
      3. 如何使用 Spring-data-elastic 查询 Elastic

        How to query Elastic with Spring-data-elastic(如何使用 Spring-data-elastic 查询 Elastic)
      4. <i id='nl3BZ'><tr id='nl3BZ'><dt id='nl3BZ'><q id='nl3BZ'><span id='nl3BZ'><b id='nl3BZ'><form id='nl3BZ'><ins id='nl3BZ'></ins><ul id='nl3BZ'></ul><sub id='nl3BZ'></sub></form><legend id='nl3BZ'></legend><bdo id='nl3BZ'><pre id='nl3BZ'><center id='nl3BZ'></center></pre></bdo></b><th id='nl3BZ'></th></span></q></dt></tr></i><div id='nl3BZ'><tfoot id='nl3BZ'></tfoot><dl id='nl3BZ'><fieldset id='nl3BZ'></fieldset></dl></div>
          <bdo id='nl3BZ'></bdo><ul id='nl3BZ'></ul>

          <small id='nl3BZ'></small><noframes id='nl3BZ'>

                <tbody id='nl3BZ'></tbody>

                  <tfoot id='nl3BZ'></tfoot>
                  <legend id='nl3BZ'><style id='nl3BZ'><dir id='nl3BZ'><q id='nl3BZ'></q></dir></style></legend>
                  本文介绍了如何使用 Spring-data-elastic 查询 Elastic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 Elastic 和 spring-data-elastic 的新手.我一直在搜索这里和网络的其他区域,但到目前为止一直无法找到我的问题的答案.我希望 SO 能提供帮助.

                  I am new to Elastic and spring-data-elastic. I am been searching here and other areas of the web, but so far have been unable to find the answer to my question. I am hoping SO might be able to help.

                  我正在索引我的 Users 表(名字、姓氏)中的一些记录,并且我希望能够允许高级搜索.例如,如果我的名字是Frances",然后输入Frank",那么系统就足够智能,可以返回记录.'Robinson' 和 'Robinsen' 等也一样.

                  I am indexing some records from my Users table (firstName, lastName) and I am looking to be able to allow advanced searching. So for example if I have the name 'Frances' and I enter 'Frank' then the system is smart enough to return the record. Same for 'Robinson' and 'Robinsen', etc.

                  我的 POJO 设置如下:

                  I've setup my POJO to be the following:

                  Public Users {
                      @Field(fieldType = FieldType.String)
                      private String firstName;
                  
                      @Field(fieldType = FieldType.String)
                      private String lastName
                  
                      // mutators
                      ...
                  
                   }
                  

                  目前我正在使用 spring-data-elastic ElasticRepository 进行搜索,如果我要允许高级搜索,我相信可能需要更改.一种选择是直接在 UserService 中使用 EntityManagerTemplate,但是我还不确定如何去做.

                  Currently I am using a spring-data-elastic ElasticRepository to do my searching, which I believe will probably have to change if I am going to allow for advanced searching. One option would be to use the EntityManager or Template directly in the UserService, however I'm not sure how to go about doing that just yet.

                  正如我所描述的问题,这是索引问题还是搜索问题或可能两者兼而有之?我不是在寻找任何人来做这项工作,只是为了给我指明正确的方向.

                  As I've described the problem, is this an indexing issue or a searching issue or possibly both? I'm not looking for anyone to do the work, just to point me in the right direction.

                  谢谢!

                  推荐答案

                  首先,不支持自动生成模糊查询,就文档告诉

                  First, there is not support for automatic fuzzy query generation, as far as the documentation tells

                  所以我们必须使用自定义存储库方法添加.

                  So we'll have to use custom repository methods additions.

                  假设您的基础存储库是

                  @Repository
                  public interface UserRepository extends CrudRepository<UserEntity, Long>
                  

                  您必须创建一个自定义存储库接口来添加您的自定义方法(这就是 标准 Spring 数据,没什么特别的)

                  You'll have to create a Custom repository interface to add you custom method (this is all standard Spring data, nothing particular)

                  public interface UserRepositoryCustom {
                      public List<User> findFuzzyByLastNameAndFirstName(String firstName, String lastName);
                  }
                  

                  并让你的历史repo实现这个接口,即:

                  And make your historic repo implement this interface, that is :

                  @Repository
                  public interface UserRepository extends CrudRepository<UserEntity, Long>, UserRepositoryCustom
                  

                  现在,您需要以某种方式实现您的自定义"界面.这很容易(再次查看手册,您必须尊重命名方案,以便 Spring 可以在运行时连接接口和实现):

                  Now, you'll need to implement your "custom" interface somehow. This is easy (once again see the manual, you have to respect naming schemes so that Spring can wire interfaces and implementations at run time):

                  public class UserRepositoryCustomImpl implements UserRepositoryCustom {
                      @Autowired protected ElasticsearchTemplate elasticsearchTemplate;
                  
                      public List<User> findFuzzyByLastNameAndFirstName(String firstName, String lastName) {
                          Criteria c = new Criteria("firstName").fuzzy(firstName).and(new Criteria("lastName").fuzzy(lastName));
                          return elasticsearchTemplate.queryForList(new CriteriaQuery(c), CandidateEntity.class);
                      }
                  }
                  

                  重新编译,重新启动,您应该可以让您的存储库像这样进行模糊搜索.

                  Recompile, relaunch, and you should be able to have your repository do the fuzzy search like so.

                  然后(请参阅问题评论),您可能还希望将查询定义为字符串,并且您不需要自定义实现.这取决于你.

                  Then again (see the questions comments), you might also want to define the query as a String and you wouldn't need custom implementations. This is up to you.

                  这篇关于如何使用 Spring-data-elastic 查询 Elastic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                  • <bdo id='TsZfV'></bdo><ul id='TsZfV'></ul>
                    • <i id='TsZfV'><tr id='TsZfV'><dt id='TsZfV'><q id='TsZfV'><span id='TsZfV'><b id='TsZfV'><form id='TsZfV'><ins id='TsZfV'></ins><ul id='TsZfV'></ul><sub id='TsZfV'></sub></form><legend id='TsZfV'></legend><bdo id='TsZfV'><pre id='TsZfV'><center id='TsZfV'></center></pre></bdo></b><th id='TsZfV'></th></span></q></dt></tr></i><div id='TsZfV'><tfoot id='TsZfV'></tfoot><dl id='TsZfV'><fieldset id='TsZfV'></fieldset></dl></div>
                        <tbody id='TsZfV'></tbody>

                          <tfoot id='TsZfV'></tfoot>

                          <legend id='TsZfV'><style id='TsZfV'><dir id='TsZfV'><q id='TsZfV'></q></dir></style></legend>

                          <small id='TsZfV'></small><noframes id='TsZfV'>