Generate the elasticsearch query and search based on defined data.
- Deploy elasticsearch in docker
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" elasticsearch:8.13.3
- Create an index with below mapping and setting
PUT http://localhost:9200/account-documents
{
"mappings": {
"properties": {
"accountNumber": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"balance": {
"type": "float"
},
"openDate": {
"type": "date"
},
"user_id": {
"type": "long"
}
}
},
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"number_of_replicas": "1"
}
}
}
- Insert the document as mentioned below
POST http://localhost:9200/account-documents/_doc
{
"accountNumber": "sandeep.rana.02",
"user_id": 13524,
"balance": 1000.00,
"openDate": "2022-02-11"
}
Change the application.properties file based on your prop.
spring.ai.mistralai.api-key=<api-key>
- Run
mvn clean install
- Run
mvn spring-boot:start
Open the browser
Use the below as sample to search
For further reference, please consider the following sections:
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Create an OCI image
- Spring Web
- OpenAI
- Elasticsearch Vector Database
- Spring Data JPA
The following guides illustrate how to use some features concretely:
- Building a RESTful Web Service
- Serving Web Content with Spring MVC
- Building REST services with Spring
- Accessing Data with JPA
Due to Maven's design, elements are inherited from the parent POM to the project POM.
While most of the inheritance is fine, it also inherits unwanted elements like <license>
and <developers>
from the parent.
To prevent this, the project POM contains empty overrides for these elements.
If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides.