2

I have multiple indices for every day in elasticsearch and I am using ElasticsearchRepository to query my documents. Documents definition:

@Getter
@Setter
@Document(indexName = "fraud-hub-digital-transactions-#{T(java.time.LocalDate).now().toString()}", createIndex = false)
@TypeAlias("fraud-hub-digital-transactions")
public class FraudDigitalTransactions {
    
    @Id
    @Field(name = "transaction_key",type = FieldType.Long)
    private Long transactionId;
    
    @Field(name = "client_no",type = FieldType.Integer)
    private Integer clientNo;
}

My index will create dynamically for every day with this definition

@Document(indexName = "fraud-hub-digital-transactions-#{T(java.time.LocalDate).now().toString()}"

My Repository definition:

@Repository
public interface FraudDigitalTransactionsRepository extends ElasticsearchRepository<FraudDigitalTransactions,String> {
    List<FraudDigitalTransactions> findByClientNo(Integer clientNo);
}

When I query by client no just returning current day values.

@Test
public void testFindByClientNo() {
    List<FraudDigitalTransactions> fraudDigitalTransactions = fraudDigitalTransactionsRepository.findByClientNo(88019237);
    Assert.assertNotEquals(fraudDigitalTransactions.size(),0);
}

Test failed. Current day values returned not searched all indices. Probably Spring data searching a document in current day indexes. Is there any way with spring data to search all indexes? I can do it with elasticsearch high-level client but I want to do with spring data features

1 Answer 1

1

You will need to search with a wildcard or alias and when writing use the index name produced by the bean.

I recently wrote a blog post how to do this with Spring Data Elasticsearch 4.1 using index templates.

Sign up to request clarification or add additional context in comments.

3 Comments

Great. Spring team really proactive. Thanks.
I'm not part of the Spring Team; Spring Data Elasticsearch is a community project ;-)
Indexes puttemplate command for alias is not working while index document does not exist. I tried create an index manually and batch uploaded data from logstash, spring application could not give alias to this index.

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.