Reputation: 103
im completely new to ElasticSearch. I have a static json file which i need to save it in ElasticSearch. I want to know how can we acheieve this using spring Java. Could someone guide me with any learning documents /or any links please.
Upvotes: 1
Views: 2353
Reputation: 1090
Could someone guide me with any learning documents /or any links please.
Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html
Spring Data Elasticsearch: http://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/
I have a static json file which i need to save it in ElasticSearch.
static static Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "your_cluster_name").build();
static TransportClient transportClient = new TransportClient(settings);
static Client client = transportClient.addTransportAddress(new InetSocketTransportAddress("192.xx.xx.xx", 9300));
client.prepareIndex("your_index_name", "your_type_name").setSource(jsonDoc).get();
I want to know how can we acheieve this using spring Java.
//Create an interface like this.
public interface YourClassRepository extends ElasticsearchRepository<YourClass, String> {}
//In your service implementation class do this.
@Autowired
private YourClassRepository yourClassRepository;
YourClass instance = new YourClass();
yourClassRepository.save(instance);
Upvotes: 2