Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query Elasticsearch using Spring Data Elasticsearch with fields containing underscore

Below is my User model

@Document(indexName="users",type="records")
public class User{
    private String id;
    private String first_name;
    private String last_name;
}

and below is my Repository

@Repository
public interface UserSearchRepository extends ElasticsearchRepository<User,String> {

    public List<User> findAllByFirst_name(String first_name);

}

The above method gives an error of

No property first found for type User

So I want to know how can I query using fieldnames containing underscores

like image 523
Harshit Bhatt Avatar asked Apr 25 '26 22:04

Harshit Bhatt


1 Answers

@JsonProperty("first_name")
private String firstName;

In @Query you can use first_name as described here.

like image 146
deepa Avatar answered Apr 28 '26 11:04

deepa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!