Alexandre T
Alexandre T

Reputation: 658

MongoDB Full Text Search with JHIPSTER / SPRING DATA MONGODB

I'm trying to do some full text queries with the last release of jhîpster (4.0.7) and spring data mongodb.

I created a repository which extends CrudRepository:

public interface PublicSearchRepository extends CrudRepository<Transcriptionrequest, String> {

  Page<Transcriptionrequest> findBy(TextCriteria textCriteria, Pageable pageable);

and apply the query as following :

TextCriteria textCriteria = TextCriteria.forDefaultLanguage().caseSensitive(Boolean.FALSE);
        textCriteria.matching(query);

Page<Transcriptionrequest> page = publicSearchRepository.findBy(textCriteria, pageable);

My object is indexed with the annotations

@Document(collection = "transcriptionrequest")
public class Transcriptionrequest implements Serializable {

    private static final long serialVersionUID = 1L;

    @TextScore
    private Float score;

    @Id
    private String id;

    @Field("request_id")
    private String request_id;

    @NotNull
    @Field("song_name")
    @TextIndexed(weight = 2)
    private String song_name;

When I try to search,I always have this error :

org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 4 and error message 'Missing expected field "$search"' on server localhost:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 4 and error message 'Missing expected field "$search"' on server localhost:27017
    at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:107)
    at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2134)
    at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1977)
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1783)
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1766)
    at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:640)

When I raised the log level of mongo classes I have the query. The search field is never sent.

Created query Query: { }, Fields: null, Sort: null
2017-03-02 22:53:45.625 DEBUG 6428 --- [ XNIO-2 task-20] o.s.data.mongodb.core.MongoTemplate      : find using query: { "$text" : { "$caseSensitive" : false}} fields: { "score" : { "$meta" : "textScore"}} for class: class info.touret.songtranscriptmarket.domain.Transcriptionrequest in collection: transcriptionrequest
2017-03-02 22:53:45.626 DEBUG 6428 --- [ XNIO-2 task-20] o.s.data.mongodb.core.MongoDbUtils       : Getting Mongo Database name=[songtranscriptmarket]

How can I fix that ?

Thanks for your help

Upvotes: 1

Views: 1836

Answers (1)

Alexandre T
Alexandre T

Reputation: 658

My query was equal to null. In this case the framework doesn't fill the $search attribute.

Upvotes: 1

Related Questions