Generator-jhipster: org.elasticsearch.search.SearchParseException: No mapping found for [id] in order to sort on

Created on 12 Jun 2017  路  15Comments  路  Source: jhipster/generator-jhipster

*Overview *

I'm not sure if i'm just overlooking something silly here, however i'm hitting this issue on my current project, and simulated in on a freshly generated jHipster application, and get the same result.

  1. Generate application using 4.5.3
  2. Select 'search using elasticsearch' option.
  3. Add a single entity 'Book' with name, description and price fields.
  4. Start up application, navigate to books entity page, then use search field:
2017-06-12 10:12:27.675 DEBUG 95115 --- [ XNIO-2 task-29] z.co.jmr.fake.aop.logging.LoggingAspect  : Enter: za.co.jmr.fake.web.rest.BookResource.searchBooks() with argument[s] = [hello, Page request [number: 0, size 20, sort: _score: DESC,id: ASC]]
2017-06-12 10:12:27.675 DEBUG 95115 --- [ XNIO-2 task-29] za.co.jmr.fake.web.rest.BookResource     : REST request to search for a page of Books for query hello
2017-06-12 10:12:27.676 DEBUG 95115 --- [ XNIO-2 task-29] z.co.jmr.fake.aop.logging.LoggingAspect  : Enter: za.co.jmr.fake.service.BookService.search() with argument[s] = [hello, Page request [number: 0, size 20, sort: _score: DESC,id: ASC]]
2017-06-12 10:12:27.676 DEBUG 95115 --- [ XNIO-2 task-29] za.co.jmr.fake.service.BookService       : Request to search for a page of Books for query hello
2017-06-12 10:12:27.745 ERROR 95115 --- [ XNIO-2 task-29] z.co.jmr.fake.aop.logging.LoggingAspect  : Exception in za.co.jmr.fake.service.BookService.search() with cause = 'SearchParseException[No mapping found for [id] in order to sort on]' and exception = 'all shards failed'

org.elasticsearch.action.search.SearchPhaseExecutionException: all shards failed
    at org.elasticsearch.action.search.AbstractSearchAsyncAction.onFirstPhaseResult(AbstractSearchAsyncAction.java:206)
    at org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:152)
    at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:46)
    at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:874)
    at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:852)
    at org.elasticsearch.transport.TransportService$4.onFailure(TransportService.java:389)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:39)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.search.SearchParseException: No mapping found for [id] in order to sort on
    at org.elasticsearch.search.sort.SortParseElement.addSortField(SortParseElement.java:213)
    at org.elasticsearch.search.sort.SortParseElement.addCompoundSortField(SortParseElement.java:187)
    at org.elasticsearch.search.sort.SortParseElement.parse(SortParseElement.java:85)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:856)
    at org.elasticsearch.search.SearchService.createContext(SearchService.java:667)
    at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:633)
    at org.elasticsearch.search.SearchService.executeDfsPhase(SearchService.java:264)
    at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:360)
    at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:357)
    at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33)
    at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:77)
    at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:378)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
    ... 3 common frames omitted
JHipster configuration
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "za.co.jmr.fake",
      "nativeLanguage": "en"
    },
    "jhipsterVersion": "4.5.3",
    "baseName": "fake",
    "packageName": "za.co.jmr.fake",
    "packageFolder": "za/co/jmr/fake",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "hibernateCache": "ehcache",
    "clusteredHttpSession": false,
    "websocket": "spring-websocket",
    "databaseType": "sql",
    "devDatabaseType": "h2Memory",
    "prodDatabaseType": "mssql",
    "searchEngine": "elasticsearch",
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "jwtSecretKey": "2b3494fe754f94a922eb807326e97abefbd5c7e3",
    "clientFramework": "angular1",
    "useSass": true,
    "clientPackageManager": "yarn",
    "applicationType": "monolith",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "en",
    "languages": [
      "en"
    ]
  }
}
Entity configuration(s) entityName.json files generated in the .jhipster directory

Book.json

{
    "fluentMethods": true,
    "relationships": [],
    "fields": [
        {
            "fieldName": "name",
            "fieldType": "String",
            "fieldValidateRules": [
                "required"
            ]
        },
        {
            "fieldName": "description",
            "fieldType": "String"
        },
        {
            "fieldName": "price",
            "fieldType": "BigDecimal",
            "fieldValidateRules": [
                "required",
                "min",
                "max"
            ],
            "fieldValidateRulesMin": "100",
            "fieldValidateRulesMax": "1000"
        }
    ],
    "changelogDate": "20170612081129",
    "dto": "no",
    "service": "serviceClass",
    "entityTableName": "book",
    "pagination": "pagination"
}

Browsers and Operating System

java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

git version 2.11.0 (Apple Git-81)

node: v8.1.0

npm: 5.0.3

bower: 1.8.0

gulp:
[10:24:30] CLI version 1.2.2
[10:24:30] Local version 3.9.1

yeoman: 1.8.5

yarn: 0.24.6

Docker version 17.06.0-ce-rc1, build 7f8486a

docker-compose version 1.13.0, build 1719ceb

needs-pr

Most helpful comment

It only happens the first time, when you have no data, so this entity is not indexed yet by Elasticsearch
Maybe we can try to catch the error, but it should not happened when you have data

All 15 comments

It only happens the first time, when you have no data, so this entity is not indexed yet by Elasticsearch
Maybe we can try to catch the error, but it should not happened when you have data

If I understand this issue correctly, actually I have the same problem. This is exactly spring-data-elasticsearch issue, and exactly just like @pascalgrimaud said, this is only happened if there's no data.

The real problem is because spring-data-elasticsearch doesn't add unmapped type for sorted field.

I have simplified version of POC to show this problem: https://github.com/xsalefter/elasticsdata/tree/spring-data . Now, at this point, I have no idea which class to changes/extends to avoid the problem gracefully.

Guys, not sure if I can piggy back on this but search on one of my entities is failing with the same error even though I have a bunch of records in the table. Following is the stack trace -

Caused by: org.elasticsearch.search.SearchParseException: No mapping found for [id] in order to sort on
at org.elasticsearch.search.sort.SortParseElement.addSortField(SortParseElement.java:213)
at org.elasticsearch.search.sort.SortParseElement.addCompoundSortField(SortParseElement.java:187)
at org.elasticsearch.search.sort.SortParseElement.parse(SortParseElement.java:85)
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:856)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:667)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:633)
at org.elasticsearch.search.SearchService.executeDfsPhase(SearchService.java:264)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:360)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:357)
at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33)
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:77)
at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:378)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
... 3 common frames omitted

@pascalgrimaud I don not understand the issue well, but anyways do you think there is anything that can be done in JHipster here or should it be deferred to spring-data?

Not sure if there is an issue, excepting the stacktrace in the log. As I already said, it should happen only in development, because:

It only happens the first time, when you have no data, so this entity is not indexed yet by Elasticsearch
Maybe we can try to catch the error, but it should not happened when you have data

In production, it should be already indexed, so there are no issue in prod

@pascalgrimaud , @deepu105 - Like I mentioned, this seems to be happening even though I have several records in my entity table. Also, the search failure actually shows up on the UI too so its not something that can be ignored as a harmless stack trace.
Having said that, I am not sure (yet) if this has anything to do with spring-data or Jhipster.

@vishwastam : I'm pretty sure your data in DB are not correctly sync with ES. You can use this module to resync https://github.com/geraldhumphries/generator-jhipster-elasticsearch-reindexer

But if you have a specific use case to reproduce this stack (excepting with empty data), plz describe all steps so we can try to reproduce

I'm not sure we should do something for that, as already said, it can only happen when there is no data in ES, so during development.

I'm closing this as there is no proposal since 1 month and the behavior for me is normal.
But don't hesitate to propose something if you want, so comment this ticket.

Actually I've run into the same issue only if I tried to modify the project (enable Elasticsearch) after the JHipster project has already been generated without Elasticsearch being enabled. So a not too precise list of reproduction steps looks like this (I can add more details if you wish):

1.) Generate a sample project (one entity) without Elasticsearch being enabled.

2.) Change "searchEngine": "false" to "searchEngine": "elasticsearch" in .yo-rc.json

3.) Execute: yo jhipster --> answer Yes to all modifications

4.) Regenerate the entity: jhipster entity <entity_name> --regenerate

5.) Build the project and start it.

6.) Log in to the entity's table and enter something to the search bar:

Result: No search result is shown and the already mentioned stacktrace is displayed.

If Elasticsearch is enabled right at the beginning, no such issue is present on my side!

Sorry I missed one step: add some data to the table of course before performing the search. I've tried running yo jhipster-elasticsearch-reindexer and rebulding the project but it did not help either.

I don't know why my new 5.1.0 project Elasticsearch still has errors even with data. I changed this.predicate = '_score' to this.predicate = 'id',problem solved.So why generator use '_score'?

I was dealing with the same issue.
My application:
Monolitic, Mysql, Development. I'm inserting the initial data with csv in Liquibase.

I have tried to run the jhipster-elasticsearch-reindexer but didn't work.
I had several problems to run the reindexer without Exceptions, but after i corrected them and reindexed the search query worked.

I runned jhipster-elasticsearch-reindexer, but the problem remained. All entities contains rows.
I realized that the error doesn't occurs with all entities, but I can't fix. Someone discovered the solution?

Edit: The bug was solved https://jira.spring.io/browse/DATAES-467

not sure if this will help, check if search repository of the new entity is at Elastic Search Index Service if you are using jhipster-elasticsearch-reindexer

If someone wants a fix for this:
Create a @PostConstruct in some @Configuration class, which does the following:

entitySearchRepository.deleteAll();
entitySearchRepository.save(entityRepository.findAll());

Do this for each of your entities.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deepu105 picture deepu105  路  81Comments

loydjayme25 picture loydjayme25  路  71Comments

jdubois picture jdubois  路  61Comments

yelhouti picture yelhouti  路  75Comments

lordlothar99 picture lordlothar99  路  76Comments