Create The Address Entity

Restaurants need locations, and to represent these locations in our application, we need an Address entity that will store all the necessary address components.

Creating the Address Class

Let's start by creating our Address class that will hold various components of a physical address.

package com.devtiro.restaurant.domain.entities; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.FieldType; @Data @AllArgsConstructor @NoArgsConstructor @Builder public class Address { @Field(type = FieldType.Keyword) private String streetNumber; @Field(type = FieldType.Text) private String streetName; @Field(type = FieldType.Keyword) private String unit; @Field(type = FieldType.Keyword) private String city; @Field(type = FieldType.Keyword) private String state; @Field(type = FieldType.Keyword) private String postalCode; @Field(type = FieldType.Keyword) private String country; }

Notice how most fields use FieldType.Keyword since they represent exact values that we don't need to analyze or search within.

The exception is streetName, which uses FieldType.Text because we might want to search within street names.

This approach aligns with how we handled field types in our User entity, where we used FieldType.Text for searchable fields and FieldType.Keyword for exact matches.

Later, we'll nest this Address entity within our Restaurant entity to create a complete restaurant record.

Summary

  • Created the Address entity class with Lombok annotations
  • Added address-specific fields with appropriate Elasticsearch annotations
  • Used FieldType.Keyword for exact-match fields like postalCode
  • Used FieldType.Text for searchable fields like streetName
  • Prepared the entity for nesting in the Restaurant entity
© 2026 Devtiro Ltd. All rights reserved