ElasticSearch

Spring Data Elasticsearch (4.x) - Using @Id forces id field in _source

人走茶凉 提交于 2021-01-27 05:18:21
问题 Summary Recently we upgraded to Spring Data Elasticsearch 4.x. Part of this major release meant that Jackson is no longer used to convert our domain objects to json (using MappingElasticsearchConverter instead) [1]. This means we are now forced to add a new id field to all our documents. Previously we had domain objects like this: import org.springframework.data.annotation.Id; public ESDocument { @Id private String id; private String field1; @JsonIgnore public String getId() { return id; }

ElasticSearch taking word order into account in match query

你离开我真会死。 提交于 2021-01-27 04:08:07
问题 Suppose that my index have two documents: "foo bar" "bar foo" When I do a regular match query for "bar foo", both documents match correctly but they get equal relevance scores. However, I want the order of words to be significant during scoring. In other words, I want "bar foo" to have a higher score. So I tried putting my match query inside the must clause of a bool query and included a match_phrase (with the same query string) as the should clause. This seems to score hits correctly, until

API 分页设计与实现探讨

我的梦境 提交于 2021-01-26 07:10:07
对于设计和实现 API 来说,当结果集包含成千上万条记录时,返回一个查询的所有结果可能是一个挑战,它给服务器、客户端和网络带来了不必要的压力,于是就有了分页的功能。 通常我们通过一个 offset 偏移量或者页码来进行分页,然后通过 API 实现类似请求: GET /api/products?page= 10 { "items" : [.. .100 products]} 如果要继续访问后续数据,则修改分页参数即可。 GET /api/products?page= 11 { "items" : [...another 100 products]} 在使用 offset 的情况下,通常使用 ?offset=1000 和 ?offset=1100 这种大家都熟悉的方法。它要么直接调用 OFFSET 1000 LIMIT 100 的 SQL 查询数据库,要么使用 LIMIT 乘以 page 作为查询参数。无论如何, 这是一个次优的解决方案 ,因为无论哪种数据库都要跳过前面 offset 指定的 1000 行。而跳过额外的offset,不管是 PostgreSQL,ElasticSearch还是 MongoDB 都存在额外开销,数据库需要对它们进行排序,计数,然后将前面不用的数据扔掉。 粉丝福利: 手撸了 50 个 Java 项目实战后,我超神了! 这是一种低效的方法,但由于它使用简单

API 分页探讨:offset 来分页真的有效率?

浪尽此生 提交于 2021-01-25 13:46:55
对于设计和实现 API 来说,当结果集包含成千上万条记录时,返回一个查询的所有结果可能是一个挑战,它给服务器、客户端和网络带来了不必要的压力,于是就有了分页的功能。 通常我们通过一个 offset 偏移量或者页码来进行分页,然后通过 API 实现类似请求: GET /api/products? page =10 { "items" : [ .. .100 products]} 如果要继续访问后续数据,则修改分页参数即可。 GET /api/products? page =11 { "items" : [ .. .another 100 products]} 在使用 offset 的情况下,通常使用 ?offset=1000 和 ?offset=1100 这种大家都熟悉的方法。它要么直接调用 OFFSET 1000 LIMIT 100 的 SQL 查询数据库,要么使用 LIMIT 乘以 page 作为查询参数。 无论如何, 「这是一个次优的解决方案」 ,因为无论哪种数据库都要跳过前面 offset 指定的 1000 行。而跳过额外的offset,不管是 PostgreSQL,ElasticSearch还是 MongoDB 都存在额外开销,数据库需要对它们进行排序,计数,然后将前面不用的数据扔掉。 这是一种低效的方法,但由于它使用简单,所以大家重复地用这个方法,也就是直接把 API

中间件:ElasticSearch组件RestHighLevelClient用法详解

心不动则不痛 提交于 2021-01-25 10:09:34
本文源码: GitHub·点这里 || GitEE·点这里 一、基础API简介 1、RestHighLevelClient RestHighLevelClient的API作为ElasticSearch备受推荐的客户端组件,其封装系统操作ES的方法,包括索引结构管理,数据增删改查管理,常用查询方法,并且可以结合原生ES查询原生语法,功能十分强大。 在使用RestHighLevelClient的语法时,通常涉及上面几个方面,在掌握基础用法之上可以根据业务特点进行一些自定义封装,这样可以更优雅的解决业务需求。 2、核心依赖 使用RestHighLevelClient需要依赖 rest-high-level-client 包,和ES相关基础依赖。 <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> </dependency> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-client</artifactId> </dependency> <dependency> <groupId>org.elasticsearch.client<

Is it possible for users to set their own timezone in Kibana?

99封情书 提交于 2021-01-25 07:26:21
问题 I'm familiar with the timezone option under the advanced settings area of Kibana, but was wondering if anyone has found a way for individual users to override this with their own setting? For reference - https://www.elastic.co/guide/en/kibana/current/advanced-options.html. The global setting for Kibana is below and not what I want to change. Ideally I'd like for each user to be able to set this to whatever they'd like. 回答1: Just leave it as Browser , this way Kibana will use the same timezone

Is it possible for users to set their own timezone in Kibana?

泄露秘密 提交于 2021-01-25 07:25:57
问题 I'm familiar with the timezone option under the advanced settings area of Kibana, but was wondering if anyone has found a way for individual users to override this with their own setting? For reference - https://www.elastic.co/guide/en/kibana/current/advanced-options.html. The global setting for Kibana is below and not what I want to change. Ideally I'd like for each user to be able to set this to whatever they'd like. 回答1: Just leave it as Browser , this way Kibana will use the same timezone

Is it possible for users to set their own timezone in Kibana?

流过昼夜 提交于 2021-01-25 07:25:09
问题 I'm familiar with the timezone option under the advanced settings area of Kibana, but was wondering if anyone has found a way for individual users to override this with their own setting? For reference - https://www.elastic.co/guide/en/kibana/current/advanced-options.html. The global setting for Kibana is below and not what I want to change. Ideally I'd like for each user to be able to set this to whatever they'd like. 回答1: Just leave it as Browser , this way Kibana will use the same timezone

Elasticsearch query issue on date-time ranges in a nested object

本秂侑毒 提交于 2021-01-25 01:41:12
问题 Hi I am using spring data Elasticsearch to form a query and have the following data indexed in my elastic search Indexed Data [ { "id": "Ef5E-HYB3sZzelDP-ie1", "name": "B", "availability": [ { "partial": false, "dates": { "gte": "2020-12-05T09:00:00", "lte": "2020-12-10T13:00:00" } } ] }, { "id": "Ev5F-HYB3sZzelDPIicy", "name": "A", "availability": [ { "partial": false, "dates": { "gte": "2020-12-01T07:00:00", "lte": "2020-12-02T12:00:00" } } ] } ] Entities public class Worker { @Id private

Elasticsearch query on array of composite objects along with date ranges

时光总嘲笑我的痴心妄想 提交于 2021-01-25 01:41:12
问题 Hi I have a question on how to create an elastic search query for a nested composite object with date ranges and additional field parameters like so [{ "name": "A", "availability": [ { "partial": true, "dates": { "gte": "2020-12-01", "lte": "2020-12-02" } } ] }, { "name": "B", "availability": [ { "partial": true, "dates": { "gte": "2020-12-05", "lte": "2020-12-06" } }, { "partial": false, "dates": { "gte": "2020-12-08", "lte": "2020-12-11" } } ] }] This is my entity data @Document(indexName =