Description
Following the post and looking at the issue #1278 I am trying to write a "complex" CriteriaQuery
@sothawo
I am on spring-data-elasticsearch 4.1.2 - has #1278 been implemented there?
I am trying to write a CriteriaQuery with semantics:
(firstName = 'A' and lastName = 'B') or ( firstName = 'C' and lastName = 'D' ) - where each record is presented by their tuples, so I expect 2 records.
I have tried:
Criteria one = Criteria.where("firstName").is( "A" ).and( "lastName" ).is( "B" );
Criteria two = Criteria.where( "firstName" ).is( "C" ).and( "lastName" ).is( "D" );
Criteria oneOrTwo = Criteria.and().or( one ).or( two );
This yields me correct number of rows however the criteriaChains seems to only match on lastName (firstName seems forgotten)
I have also tried:
Criteria one = Criteria.where("firstName").is( "A" ).and( "lastName" ).is( "B" );
Criteria two = Criteria.where( "firstName" ).is( "C" ).and( "lastName" ).is( "D" );
Criteria oneOrTwo = one.or( two );
This yields only the "one" record.
I also tried:
Criteria.and().subCriteria( Criteria.or().subCriteria( one ).subCriteria( two ) )
This yields me correct results.
However when passing an object as Date value, these subCriteria values do not get converted by MappingElasticsearchConverter.updateCriteria()
.
This is because there is no criteriaChain - just subCriteria's and thus the following function bails out ?
@Override
public void updateCriteriaQuery(CriteriaQuery criteriaQuery, Class<?> domainClass) {
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(domainClass);
if (persistentEntity != null) {
for (Criteria chainedCriteria : criteriaQuery.getCriteria().getCriteriaChain()) {
updateCriteria(chainedCriteria, persistentEntity);
}
}
}
Is this possible that this case is not correctly implemented, or am I just doing it wrong.
In case this is a bug, could you/we add documentation on how more complex queries like this need to be handled with CriteriaQuery?