elasticsearchsearchliferay-7liferay-service-builder

Liferay 7 search not returning results - Custom entity


I'm trying to enable search for a custom entity, I've implemented the indexer and trying to execute search as below but the search doesn't return any document/results

    SearchContext searchContext = SearchContextFactory.getInstance(request);
    searchContext.setKeywords(keywords);
    searchContext.setAttribute("paginationType", "more");
    searchContext.setStart(0);
    searchContext.setEnd(10);


    Indexer indexer = IndexerRegistryUtil.getIndexer(Position.class);
    Hits hits = indexer.search(searchContext);
    System.out.println("Hit count: " + hits.getLength());

The indexer implementation seems to be working, as I can see the records indexed as expected using built-in elastic search console

localhost:9200/liferay-20116/_search

Any clue what can be the possible problem??

Just for additional info, my custom entity doesn't contain a field for 'groupId'


Solution

  • Look like for some reason you must have groupId in your entity in order for the search to work unless you are willing to dig and override the behavior

    I added groupId to my entity (though I was not interested) and boom, it worked