[英]Elastic Spring Data OR Java High Level REST Client?
I'm new to both Elasticsearch and Spring.我是 Elasticsearch 和 Spring 的新手。 I've written a Javascript POC that converts a JSON string into an Elasticsearch query (and performs the request).
我编写了一个 Javascript POC,它将 JSON 字符串转换为 Elasticsearch 查询(并执行请求)。 It takes a string like this:
它需要一个这样的字符串:
{
"period": "years",
"format": "xml",
"criteria": {
"operator": "OR",
"operands": [
{
"operator": "AND",
"operands": [
{
"operator": "exists",
"field": "def"
},
{
"operator": "includes",
"field": "keywords",
"value": [
"abcd"
]
}
]
},
{
"operator": "AND",
"operands": [
{
"operator": "from",
"field": "links",
"value": 1
},
{
"operator": "includes",
"field": "keywords",
"value": [
"abcd",
"efgh"
]
}
]
}
]
}
}
(Note: This query may have any levels of nesting) (注意:此查询可能有任何级别的嵌套)
... and converts it into this: ...并将其转换为:
{
"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"bool": {
"must": [
{
"exists": {
"field": "def"
}
},
{
"range": {
"effectiveDate": {
"gte": 1543982400,
"lt": 1575518400
}
}
}
]
}
},
{
"bool": {
"must": [
{
"terms": {
"keywords.name": [
"abcd",
"efgh"
]
}
},
{
"range": {
"effectiveDate": {
"gte": 1543982400,
"lt": 1575518400
}
}
}
]
}
}
]
}
},
{
"bool": {
"must": [
{
"bool": {
"must": {
"terms": {
"links": [
11048,
34618,
34658
]
}
}
}
},
{
"bool": {
"must": [
{
"terms": {
"keywords.name": [
"abcd",
"efgh"
]
}
},
{
"range": {
"effectiveDate": {
"gte": 1543982400,
"lt": 1575518400
}
}
}
]
}
}
]
}
}
]
}
}
}
},
"size": 0,
"aggs": {
"by_id": {
"composite": {
"sources": [
{
"agg_on_id": {
"terms": {
"field": "id"
}
}
}
],
"size": 10000,
"after": {
"agg_on_id": -1
}
},
"aggs": {
"latest_snapshot": {
"top_hits": {
"sort": [
{
"effectiveDate": "desc"
}
],
"_source": true,
"size": 1
}
}
}
}
}
}
It first creates a query (similar to above) for a first trip to Elasticsearch to extract some info ('links') needed for building this query.它首先为第一次访问 Elasticsearch 创建一个查询(类似于上面),以提取构建此查询所需的一些信息(“链接”)。 Each trip to Elasticsearch may return millions of results, so it does paging using the "search_after" mechanism.
每次到 Elasticsearch 的行程可能会返回数百万个结果,因此它使用“search_after”机制进行分页。 I need to convert this POC to a Spring application.
我需要将此 POC 转换为 Spring 应用程序。
Question : Which one is most appropriate for this case - Spring Data Elasticsearch or Elasticsearch Java High Level REST Client? Question : Which one is most appropriate for this case - Spring Data Elasticsearch or Elasticsearch Java High Level REST Client? Spring data elasticsearch seems to do a good job at creating simple queries without much effort, but would it help me in this case?
Spring 数据 elasticsearch 似乎在创建简单查询方面做得很好,但在这种情况下对我有帮助吗? Any suggestions are be much appreciated.
任何建议都将不胜感激。 Thanks!
谢谢!
Spring Data Elasticsearch uses the high level client provided by Elasticsearch for the non-reactive implementation. Spring 数据 Elasticsearch 使用 Elasticsearch 提供的高级客户端进行非反应式实现。
You can use the query builders from Elasticsearch together with Spring Data Elasticsearch too, this gives you the greatest flexibility.您也可以将 Elasticsearch 中的查询构建器与 Spring 数据 Elasticsearch 一起使用,这为您提供了最大的灵活性。
Spring Data Elasticsearch puts on top of that the entity mapping (POJO to JSON), repository functions and the other stuff from Spring Data. Spring 数据 Elasticsearch 将实体映射(POJO 到 JSON)、存储库函数和 Spring 数据中的其他内容放在首位。 So it's not a question if you should do the one or the other, but if you need or want to use the additional functionality that Spring Data Elasticsearch offers.
因此,您是否应该做其中一个不是问题,但如果您需要或想要使用 Spring Data Elasticsearch 提供的附加功能。
Edit:编辑:
When using Spring Data Elasticsearch, you configure the used RestHighLevelClient
(see the documentation ) and then have it injected into your other Spring beans.使用 Spring 数据 Elasticsearch 时,您配置使用的
RestHighLevelClient
(请参阅文档),然后将其注入您的其他 Spring bean。 So you can even mix access to ES using Spring Data ElasticsearchOperations
or Repositories and access by using the RestHighLevelClient
directly.因此,您甚至可以混合使用 Spring Data
ElasticsearchOperations
或 Repositories 访问 ES,并直接使用RestHighLevelClient
进行访问。
I would suggest you use the official Java-high-level rest-client which is being worked on actively at Elastic and you can also look at all the queries builders it supports(it has got query builders for almost all the queries ).我建议您使用 Elastic 正在积极开发的官方 Java 高级别的休息客户端,您还可以查看它支持的所有查询构建器(它为几乎所有查询提供了查询构建器)。
Also previously Elasticsearch didn't have an official client for JAVA but now as they have and actively improving and developing, IMHO you should go ahead with them as it also provides a lot of out of box options and who understand Elasticsearch better than the company behind it:) Also previously Elasticsearch didn't have an official client for JAVA but now as they have and actively improving and developing, IMHO you should go ahead with them as it also provides a lot of out of box options and who understand Elasticsearch better than the company behind它:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.