@yrodiere thank you for the response.
I only plan to use Hibernate Search to write documents, execute searches, and read documents to/from Elasticsearch. I do not plan to use it to create my indexes (setting, mappings, aliases, etc) or any other type of management. My thought process her is that I don’t use Hibernate ORM to manage my relational database schemas in a production environment so why should Hibernate Search do the same for my search engine? For databases, we have tools like Flyway and Liquibase for handling database schema migrations and I have something similar for Elasticsearch. The other thought on this is that there is so much Elasticsearch provides in terms of functionality and options for organizing your data based on your use case, I want to work as natively with it for the most flexibility.
The exception I received was
Unknown index name encountered in Elasticsearch response: ‘myapplication-myobject-v1’
and this was my setup:
- I have Hibernate Search index management disabled by default
hibernate.search.backends.elasticsearch.index_defaults.lifecycle.strategy=none
- I created an Index Template in Elasticsearch for indexes that match the pattern
myapplication-myobject-*
- I created an Index in Elasticsearch for my search documents
myapplication-myobject-v1
- I created an Index Alias in Elasticsearch that points
myapplication-myobject
to myapplication-myobject-v1
- I annotated my entity
MyObject
with @Indexed
and gave it a value that matched the alias myapplication-myobject
@Entity
// ... other hibernate annotations ...
@Indexed(index = "myapplication-myobject")
public class MyObject {
// ... properties ...
}
- I saved an instance of
MyObject
and Hibernate successfully wrote the record to the database and a document to my Elasticserch index, via my alias
- I executed an Elasticsearch search via Hibernate Search against the alias
myapplication-myobject
and it pulled back results but then threw the below exception.
Digging through the code, I found that it only maps the value in the @Indexed
annotation with the object type being annotated. It then looks that the field _index
in the search result hits in order to match the the target object type. However, in this setup, the value for _index
is the actual index name myapplication-myobject-v1
and not the alias that is in the annotation with points to the index.
Here is the full stack trace:
2019-09-19 15:16:19.012 ERROR 1304 --- [port thread - 2] o.h.s.engine.common.spi.LogErrorHandler : HSEARCH000058: Exception occurred org.hibernate.search.util.common.SearchException: HSEARCH400007: Elasticsearch request failed: HSEARCH400531: Unknown index name encountered in Elasticsearch response: 'myapplication-myobject-v1'
Context: backend 'elasticsearch'
Request: POST /myapplication-myobject/_search with parameters {size=10000, track_total_hits=true}
Response: 200 'OK' with body
{
"took": 18,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.2876821,
"hits": [
{
"_index": "myapplication-myobject-v1",
"_type": "_doc",
"_id": "9d8d70f6-60e9-4701-991e-7f3607d15f77",
"_score": 0.2876821,
"_source": {
"createdDate": "2019-09-19T20:15:40.893956000Z",
"lastModifiedDate": "2019-09-19T20:15:40.893956000Z",
"foo": "bar"
}
}
]
}
}
Primary Failure:
SearchWork[path = /myapplication-myobject/_search, refreshedIndexName = null, refreshStrategy = NONE]Subsequent failures:
SearchWork[path = /myapplication-myobject/_search, refreshedIndexName = null, refreshStrategy = NONE]
org.hibernate.search.util.common.SearchException: HSEARCH400007: Elasticsearch request failed: HSEARCH400531: Unknown index name encountered in Elasticsearch response: 'myapplication-myobject-v1'
Context: backend 'elasticsearch'
Request: POST /myapplication-myobject/_search with parameters {size=10000, track_total_hits=true}
Response: 200 'OK' with body
{
"took": 18,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.2876821,
"hits": [
{
"_index": "myapplication-myobject-v1",
"_type": "_doc",
"_id": "9d8d70f6-60e9-4701-991e-7f3607d15f77",
"_score": 0.2876821,
"_source": {
"createdDate": "2019-09-19T20:15:40.893956000Z",
"lastModifiedDate": "2019-09-19T20:15:40.893956000Z",
"foo": "bar"
}
}
]
}
}
at org.hibernate.search.backend.elasticsearch.work.impl.AbstractSimpleElasticsearchWork.handleResult(AbstractSimpleElasticsearchWork.java:108) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.work.impl.AbstractSimpleElasticsearchWork.lambda$execute$3(AbstractSimpleElasticsearchWork.java:71) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1072) ~[na:na]
at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506) ~[na:na]
at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073) ~[na:na]
at org.hibernate.search.backend.elasticsearch.client.impl.ElasticsearchClientImpl$1.onSuccess(ElasticsearchClientImpl.java:115) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.elasticsearch.client.RestClient$FailureTrackingResponseListener.onSuccess(RestClient.java:836) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
at org.elasticsearch.client.RestClient$1.completed(RestClient.java:538) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
at org.elasticsearch.client.RestClient$1.completed(RestClient.java:529) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:122) ~[httpcore-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:181) ~[httpasyncclient-4.1.4.jar:4.1.4]
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:448) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:338) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81) ~[httpasyncclient-4.1.4.jar:4.1.4]
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39) ~[httpasyncclient-4.1.4.jar:4.1.4]
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591) ~[httpcore-nio-4.4.12.jar:4.4.12]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: org.hibernate.search.util.common.SearchException: HSEARCH400531: Unknown index name encountered in Elasticsearch response: 'myapplication-myobject-v1'
Context: backend 'elasticsearch'
at org.hibernate.search.backend.elasticsearch.impl.ElasticsearchBackendImpl.lambda$new$0(ElasticsearchBackendImpl.java:93) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at java.base/java.util.Optional.map(Optional.java:265) ~[na:na]
at org.hibernate.search.backend.elasticsearch.search.projection.impl.DocumentReferenceExtractorHelper.extractDocumentReference(DocumentReferenceExtractorHelper.java:41) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.search.projection.impl.ElasticsearchEntityProjection.extract(ElasticsearchEntityProjection.java:34) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.search.query.impl.Elasticsearch7SearchResultExtractor.extractHits(Elasticsearch7SearchResultExtractor.java:73) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.search.query.impl.Elasticsearch7SearchResultExtractor.extract(Elasticsearch7SearchResultExtractor.java:56) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.work.impl.SearchWork.generateResult(SearchWork.java:51) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.work.impl.SearchWork.generateResult(SearchWork.java:27) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.work.impl.AbstractSimpleElasticsearchWork.handleResult(AbstractSimpleElasticsearchWork.java:97) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
... 23 common frames omitted
2019-09-19 15:16:19.016 ERROR 1304 --- [nio-9002-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.hibernate.search.util.common.SearchException: HSEARCH400007: Elasticsearch request failed: HSEARCH400531: Unknown index name encountered in Elasticsearch response: 'myapplication-myobject-v1'
Context: backend 'elasticsearch'
Request: POST /myapplication-myobject/_search with parameters {size=10000, track_total_hits=true}
Response: 200 'OK' with body
{
"took": 18,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.2876821,
"hits": [
{
"_index": "myapplication-myobject-v1",
"_type": "_doc",
"_id": "9d8d70f6-60e9-4701-991e-7f3607d15f77",
"_score": 0.2876821,
"_source": {
"createdDate": "2019-09-19T20:15:40.893956000Z",
"lastModifiedDate": "2019-09-19T20:15:40.893956000Z",
"foo": "bar"
}
}
]
}
}
] with root cause
org.hibernate.search.util.common.SearchException: HSEARCH400531: Unknown index name encountered in Elasticsearch response: 'myapplication-myobject-v1'
Context: backend 'elasticsearch'
at org.hibernate.search.backend.elasticsearch.impl.ElasticsearchBackendImpl.lambda$new$0(ElasticsearchBackendImpl.java:93) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at java.base/java.util.Optional.map(Optional.java:265) ~[na:na]
at org.hibernate.search.backend.elasticsearch.search.projection.impl.DocumentReferenceExtractorHelper.extractDocumentReference(DocumentReferenceExtractorHelper.java:41) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.search.projection.impl.ElasticsearchEntityProjection.extract(ElasticsearchEntityProjection.java:34) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.search.query.impl.Elasticsearch7SearchResultExtractor.extractHits(Elasticsearch7SearchResultExtractor.java:73) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.search.query.impl.Elasticsearch7SearchResultExtractor.extract(Elasticsearch7SearchResultExtractor.java:56) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.work.impl.SearchWork.generateResult(SearchWork.java:51) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.work.impl.SearchWork.generateResult(SearchWork.java:27) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.work.impl.AbstractSimpleElasticsearchWork.handleResult(AbstractSimpleElasticsearchWork.java:97) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.hibernate.search.backend.elasticsearch.work.impl.AbstractSimpleElasticsearchWork.lambda$execute$3(AbstractSimpleElasticsearchWork.java:71) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1072) ~[na:na]
at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506) ~[na:na]
at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073) ~[na:na]
at org.hibernate.search.backend.elasticsearch.client.impl.ElasticsearchClientImpl$1.onSuccess(ElasticsearchClientImpl.java:115) ~[hibernate-search-backend-elasticsearch-6.0.0.Alpha9.jar:6.0.0.Alpha9]
at org.elasticsearch.client.RestClient$FailureTrackingResponseListener.onSuccess(RestClient.java:836) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
at org.elasticsearch.client.RestClient$1.completed(RestClient.java:538) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
at org.elasticsearch.client.RestClient$1.completed(RestClient.java:529) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:122) ~[httpcore-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:181) ~[httpasyncclient-4.1.4.jar:4.1.4]
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:448) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:338) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81) ~[httpasyncclient-4.1.4.jar:4.1.4]
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39) ~[httpasyncclient-4.1.4.jar:4.1.4]
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) ~[httpcore-nio-4.4.12.jar:4.4.12]
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591) ~[httpcore-nio-4.4.12.jar:4.4.12]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
In terms of how I would want to see it work, that’s a bit of a tough question because there are so many factors. For this use case, and for Elasticsearch ILM use case, there at least needs to be a means of informing Hibernate Search the following for any given entity:
- a write alias to use for document inserts
- an alias to use for document pulls, updates and searches
- a pattern for matching the index the document exists in, or, alternatively, Hibernate Search should not use the index name for matching at all and should use some other field.
I hope this makes it more clear. I’ll wait for a response before creating the JIRA ticket as you may have feedback that would be usefull in creating such a ticket.