spring-data-elasticsearch

Spring-Data elastic search repo count with custom @Query annotation not working “Expected 1 but found 30 results”

有些话、适合烂在心里 提交于 2021-01-29 19:56:18
问题 For my application I have to perform a custom count on elastic, I want to use the @Query annotation for this in the ElasticsearchCrudRepository we use. When I use the following signature: @Query("CUSTOM BOOL QUERY HERE") long countItemsCustom(); This leads to a java.lang.IllegalArgumentException: Expected 1 but found 30 results Exception since it is executed as an query instead of an count. For spring-data-cassandra we have a special @CountQuery annotation to solve this issue. Is there a

Can we avoid mapping all the fields to entity class in springdata for elasticsearch, as I have more than 100 field in the json document?

早过忘川 提交于 2021-01-29 09:13:13
问题 I am implementing a spring-boot microservice for elasticsearch (es) operations using springdata APIs. My documents that are indexed in es are huge with multiple fields (more than 100). Is there a way to avoid defining/hardcoding all the fields in the entity class for elasticsearch object in java? My sample patient JSON could be like: { "key_1":"value_1", "key_2":"value_2", "key_3":"value_3", . . . "key_n":"value_n" } 回答1: If you can go for a slightly different form to store your data in

In “spring-data-elasticsearch” 4.0.4.RELEASE, how to convert SearchHits to Page?

前提是你 提交于 2021-01-28 08:45:58
问题 In spring-data-elasticsearch 4.0.4.RELEASE, ElasticsearchRestTemplate 's queryForPage() methods are deprecated, need to use search() instead, which return SearchHits instead of Page . So, how to convert SearchHits to Page , or how to still get results as Page ? I have searched via google, and checked official doc, and checked source code, still don't know the best way, any help? 回答1: The Query parameter to be passed into the search() method can have a Pageable set for the request. To wrap the

Spring Data Elasticsearch requires property named id

假如想象 提交于 2021-01-27 06:03:18
问题 I started to work with Spring Data Elasticsearch and find issue. During run test which is calling findAll() through repository I am getting: No id property found for class com.example.domain.entity.Project! When I add field @Transient private Long id; in my Project entity then I am able to retrieve results correctly. But I do not want to add this field because I have already defined primary key named projectId . There is annotation @Id for that field also, so why my field projectId is not

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

旧时模样 提交于 2021-01-27 05:19:12
问题 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; }

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

蓝咒 提交于 2021-01-27 05:19:08
问题 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; }

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 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 =

How to format date correctly using Spring Data Elasticsearch

不羁的心 提交于 2021-01-24 09:46:32
问题 I'm using SpringBoot 2.2.5 with Elasticsearch 6.8.6. I'm in progress of migrating from Spring Data Jest to using the Spring Data Elasticsearch REST transport mechanism with ElasticsearchEntityMapper . I have a Date field with the following definition: @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ") @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ") private Date date; I would like the date stored in