generator-jhipster: ElasticSearch fails on default sort order when no indexed data

Overview of the issue

Search fails on default sort order when using ElasticSearch + MongoDB, it can not sort by ID.

stacktrace
2018-11-03 12:15:12.062 ERROR 13570 --- [ XNIO-2 task-12] c.factly.dega.aop.logging.LoggingAspect  : Exception in com.factly.dega.service.impl.PostServiceImpl.search() with cause = 'NULL' and exception = 'Cannot execute jest action , response code : 400 , error : {"root_cause":[{"type":"query_shard_exception","reason":"No mapping found for [id] in order to sort on","index_uuid":"I0HBCJyySLmFFAbdeCw1HA","index":"post"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"dfs","grouped":true,"failed_shards":[{"shard":0,"index":"post","node":"32_5J6enRlCIpF0r6ZAa8w","reason":{"type":"query_shard_exception","reason":"No mapping found for [id] in order to sort on","index_uuid":"I0HBCJyySLmFFAbdeCw1HA","index":"post"}}]} , message : null'

com.github.vanroy.springdata.jest.exception.JestElasticsearchException: Cannot execute jest action , response code : 400 , error : {"root_cause":[{"type":"query_shard_exception","reason":"No mapping found for [id] in order to sort on","index_uuid":"I0HBCJyySLmFFAbdeCw1HA","index":"post"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"dfs","grouped":true,"failed_shards":[{"shard":0,"index":"post","node":"32_5J6enRlCIpF0r6ZAa8w","reason":{"type":"query_shard_exception","reason":"No mapping found for [id] in order to sort on","index_uuid":"I0HBCJyySLmFFAbdeCw1HA","index":"post"}}]} , message : null
	at com.github.vanroy.springdata.jest.mapper.DefaultErrorMapper.mapError(DefaultErrorMapper.java:30)
	at com.github.vanroy.springdata.jest.JestElasticsearchTemplate.execute(JestElasticsearchTemplate.java:1218)
	at com.github.vanroy.springdata.jest.JestElasticsearchTemplate.execute(JestElasticsearchTemplate.java:1208)
	at com.github.vanroy.springdata.jest.JestElasticsearchTemplate.executeSearch(JestElasticsearchTemplate.java:1321)
	at com.github.vanroy.springdata.jest.JestElasticsearchTemplate.doSearch(JestElasticsearchTemplate.java:1308)
	at com.github.vanroy.springdata.jest.JestElasticsearchTemplate.queryForPage(JestElasticsearchTemplate.java:407)
	at com.github.vanroy.springdata.jest.JestElasticsearchTemplate.queryForPage(JestElasticsearchTemplate.java:398)
	at com.github.vanroy.springdata.jest.JestElasticsearchTemplate.queryForPage(JestElasticsearchTemplate.java:90)
	at org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.search(AbstractElasticsearchRepository.java:209)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:377)
	at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:641)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy161.search(Unknown Source)
	at com.factly.dega.service.impl.PostServiceImpl.search(PostServiceImpl.java:106)

Motivation for or Use Case
Reproduce the error
  • Create an application with MongoDB and ElasticSearch
  • Create one entity with search
  • Perform any search on the ui
JHipster configuration

Using JHipster version installed locally in current project’s node_modules Executing jhipster:info Options: from-cli: true Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
jhipster@0.0.0 /home/workspaces/jhipster/projects/mongo-elastic-2
└── generator-jhipster@5.5.0 

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.factly.dega",
      "nativeLanguage": "en"
    },
    "jhipsterVersion": "5.5.0",
    "applicationType": "monolith",
    "baseName": "jhipster",
    "packageName": "com.factly.dega",
    "packageFolder": "com/factly/dega",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "hazelcast",
    "enableHibernateCache": false,
    "websocket": false,
    "databaseType": "mongodb",
    "devDatabaseType": "mongodb",
    "prodDatabaseType": "mongodb",
    "searchEngine": "elasticsearch",
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
    "clientFramework": "angularX",
    "useSass": true,
    "clientPackageManager": "npm",
    "testFrameworks": [
      "gatling",
      "cucumber",
      "protractor"
    ],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "en",
    "languages": [
      "en",
      "hi"
    ]
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Post {
  name String required
}
dto Post with mapstruct
paginate Post with pagination
service Post with serviceImpl
search Post with elasticsearch

Environment and Tools

java version “1.8.0_171” Java™ SE Runtime Environment (build 1.8.0_171-b11) Java HotSpot™ 64-Bit Server VM (build 25.171-b11, mixed mode)

git version 2.17.1

node: v8.12.0

npm: 6.4.1

yeoman: 2.0.1

yarn: 1.10.1

Docker version 17.12.1-ce, build 7390fc6

docker-compose version 1.17.1, build unknown

Browsers and Operating System
  • Checking this box is mandatory (this is just to show you read everything)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 21 (18 by maintainers)

Commits related to this issue

Most upvoted comments

It works once I add @Field(type = FieldType.Keyword) above the ID field in the entity I search on. Otherwise, I get the same stacktrace:

{"type":"query_shard_exception","reason":"No mapping found for [id] in order to sort on","index_uuid":"s8qAtj7lQ3uTmIMSA6CFlw","index":"foo"}

Yes, this version, elasticsearch will fail to run. The problem is with the log4j-core and log4j-api packages that are not entered into pom.xml. Add the bottom to pom.xml, to resolve the problem.   <dependency>              <groupId> org.apache.logging.log4j </ groupId>              <artifactId> log4j-api </ artifactId>              <version> 2.7 </ version>          </ dependency>          <dependency>              <groupId> org.apache.logging.log4j </ groupId>              <artifactId> log4j-core </ artifactId>              <version> 2.7 </ version>          </ dependency>