Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to read/write from/to Elasticsearch [BATCH-2267] #1336

Closed
spring-issuemaster opened this issue Jul 6, 2014 · 3 comments
Closed

Add support to read/write from/to Elasticsearch [BATCH-2267] #1336

spring-issuemaster opened this issue Jul 6, 2014 · 3 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Jul 6, 2014

Hasnain Javed opened BATCH-2267 and commented

To index a document via ElasticsearchItemWriter

@Document(indexName="some_index", type="some_type")
public class SomeClass {
   // field(s) with getter(s) and setter(s)
}

Create an item processor

	
public class SampleItemProcess implements ItemProcessor<Object, IndexQuery> {

   @Override
   public IndexQuery process(Object item) throws Exception {
			
      SomeClass someClass = new SomeClass();
      // pouplate someClass from item (Object)
			
      IndexQueryBuilder builder = new IndexQueryBuilder();
      builder.withObject(someClass);
     // use other methods on builder as required
			
     return builder.build();
  }
}

To read via ElasticsearchItemReader

@Configuration
public static class ReaderConfig {
		
		@Bean
		public ElasticsearchItemReader<SomeInputClass> elasticsearchItemReader() {
			
			return new ElasticsearchItemReader<>(elasticsearchOperations(), query(), SomeInputClass.class);
		}
		
		@Bean
		public SearchQuery query() {
			
			NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder();
			// create query as required using the methods on the builder object
			
			return builder.build();
		}
		
		@Bean
		public ElasticsearchOperations elasticsearchOperations() {
			// configure and return elastic search template 
		}
	}

NOTE : The Pageable object from the Query object will be used for paged requests. Setting the page and pageSize fields (inherited from AbstractPaginatedDataItemReader) will have no effect.


Affects: 4.0.0

Referenced from: pull request spring-projects/spring-batch-extensions#3, and commits spring-projects/spring-batch-extensions@c1172cf, spring-projects/spring-batch-extensions@c59aa88

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 6, 2014

Michael Minella commented

This really belongs as a module in the spring-batch-extensions project found here: https://github.com/spring-projects/spring-batch-extensions for two reasons:

  1. Prevents adding another dependency to Spring Batch
  2. Allows these components to have an independent release cycle from Spring Batch.

I added a comment to the PR to please create it as a PR for the extensions repo.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 6, 2014

Hasnain Javed commented

No problemo. Thank you for pointing me to the right direction. Apologies for any inconvenience(s) caused. Will do it as soon as I can.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 7, 2014

Hasnain Javed commented

PR for the extensions repo created. PR url updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.