The Best way to use ElasticSearch in Spring java framework(在 Spring java 框架中使用 ElasticSearch 的最佳方式)
问题描述
我正在开发一个系统,计划将弹性搜索用作数据存储库.我正在尝试选择开发我的应用程序的最佳方式,该应用程序可以索引和查询来自 elasticsearch 的数据.我的系统是建立在 Spring 框架之上的.
I'm developing a system which is planning to use elasticsearch as an data repository. I'm trying to choose the best way to develop my application that can index and query data from elasticsearch. The system I have is built on top of Spring framework.
使用Spring-data-elasticsearch(https:///github.com/spring-projects/spring-data-elasticsearch)?
或者使用elasticsearch核心库本身是一个不错的选择?
Or is it a good choice to use elasticsearch core libraries itself?
我需要处理嵌套数据(内部对象),但 Spring-data-elasticsearch 最近似乎没有任何操作.
I need to handle nested data (inner object) but Spring-data-elasticsearch seems to have no operations for that recently.
我希望我能找到问题的解决方案.提前致谢.
I hope I can find a solution for the question. Thanks in advance.
推荐答案
Spring data elasticsearch支持elasticsearch的大部分常用功能集,包括Nested、Inner Objects和Parent Child(最近).
Spring data elasticsearch supports most of the common feature set of elasticsearch including Nested, Inner Objects and Parent Child (recently).
当您说要使用嵌套数据(内部对象)时,请清楚elasticsearch有两个概念:内部对象和嵌套对象.
When you said that want to use nested data (inner object), please be clear as elasticsearch has two concepts: Inner Object and Nested Object.
详细解释可以在在elasticsearch中管理关系找到
个人实体:
@Document(indexName = "person" , type = "user")
public class Person {
@Id
private String id;
private String name;
@Field( type = FieldType.Nested)
private List<Car> car;
// setters-getters
}
汽车实体:
public class Car {
private String name;
private String model;
//setters and getters
}
设置数据:
Person foo = new Person();
foo.setName("Foo");
foo.setId("1");
List<Car> cars = new ArrayList<Car>();
Car subaru = new Car();
subaru.setName("Subaru");
subaru.setModel("Imprezza");
cars.add(subaru);
foo.setCar(cars);
索引:
IndexQuery indexQuery = new IndexQuery();
indexQuery.setId(foo.getId());
indexQuery.setObject(foo);
//creating mapping
elasticsearchTemplate.putMapping(Person.class);
//indexing document
elasticsearchTemplate.index(indexQuery);
//refresh
elasticsearchTemplate.refresh(Person.class, true);
搜索:
QueryBuilder builder = nestedQuery("car", boolQuery()
.must(termQuery("car.name", "subaru"))
.must(termQuery("car.model", "imprezza")));
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);
您可以在 嵌套对象测试
这篇关于在 Spring java 框架中使用 ElasticSearch 的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Spring java 框架中使用 ElasticSearch 的最佳方式
基础教程推荐
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01