1

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.

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.