Skip to content

Commit

Permalink
HSEARCH-3752 Support implicit nested exist (field) predicates in ES
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Mar 18, 2020
1 parent 410a7c5 commit 1bedbad
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Expand Up @@ -6,21 +6,24 @@
*/
package org.hibernate.search.backend.elasticsearch.search.predicate.impl;

import java.util.List;

import org.hibernate.search.backend.elasticsearch.gson.impl.JsonAccessor;
import org.hibernate.search.backend.elasticsearch.gson.impl.JsonObjectAccessor;
import org.hibernate.search.engine.search.predicate.spi.ExistsPredicateBuilder;

import com.google.gson.JsonObject;

public class ElasticsearchExistsPredicateBuilder extends AbstractElasticsearchSearchPredicateBuilder
public class ElasticsearchExistsPredicateBuilder extends AbstractElasticsearchSearchNestedPredicateBuilder
implements ExistsPredicateBuilder<ElasticsearchSearchPredicateBuilder> {

private static final JsonObjectAccessor EXISTS_ACCESSOR = JsonAccessor.root().property( "exists" ).asObject();
private static final JsonAccessor<String> FIELD_ACCESSOR = JsonAccessor.root().property( "field" ).asString();

private final String absoluteFieldPath;

ElasticsearchExistsPredicateBuilder(String absoluteFieldPath) {
ElasticsearchExistsPredicateBuilder(String absoluteFieldPath, List<String> nestedPathHierarchy) {
super( nestedPathHierarchy );
this.absoluteFieldPath = absoluteFieldPath;
}

Expand Down
Expand Up @@ -143,7 +143,7 @@ public ExistsPredicateBuilder<ElasticsearchSearchPredicateBuilder> exists(String
// We may be able to relax this constraint, but that would require more extensive testing
scopeModel.getSchemaNodeComponent( absoluteFieldPath, PREDICATE_BUILDER_FACTORY_RETRIEVAL_STRATEGY );
}
return new ElasticsearchExistsPredicateBuilder( absoluteFieldPath );
return new ElasticsearchExistsPredicateBuilder( absoluteFieldPath, scopeModel.getNestedPathHierarchy( absoluteFieldPath ) );
}

@Override
Expand Down
Expand Up @@ -167,6 +167,11 @@ public void predicate_geoCircle() {
verify_implicit_nest( p -> p.spatial().within().field( "nested.geo" ).circle( G11, 1 ) );
}

@Test
public void predicate_exists_field() {
verify_implicit_nest( p -> p.exists().field( "nested.geo" ) );
}

@Test
public void predicate_simpleQueryString_multipleNestedPaths() {
SubTest.expectException( () -> indexManager.createScope()
Expand Down
Expand Up @@ -41,6 +41,7 @@
import org.hibernate.search.util.impl.test.SubTest;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

Expand Down Expand Up @@ -224,6 +225,7 @@ public void inFlattenedObject_withDocValues() {
* Querying fields of a nested object without a nested predicate should result in no result at all.
*/
@Test
@Ignore // TODO HSEARCH-3752 restore the test with the new assumptions
public void inNestedObject() {
StubMappingScope scope = indexManager.createScope();

Expand Down

0 comments on commit 1bedbad

Please sign in to comment.