Fixed resolving closest nested object when sorting on a field inside nested object
This commit is contained in:
parent
c751df5ee5
commit
2b5e3f5586
|
@ -242,18 +242,24 @@ public class SortParseElement implements SearchParseElement {
|
|||
int indexOf = fieldName.lastIndexOf('.');
|
||||
if (indexOf == -1) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
do {
|
||||
String objectPath = fieldName.substring(0, indexOf);
|
||||
ObjectMappers objectMappers = context.mapperService().objectMapper(objectPath);
|
||||
if (objectMappers == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String objectPath = fieldName.substring(0, indexOf);
|
||||
ObjectMappers objectMappers = context.mapperService().objectMapper(objectPath);
|
||||
if (objectMappers == null) {
|
||||
return null;
|
||||
}
|
||||
if (objectMappers.hasNested()) {
|
||||
for (ObjectMapper objectMapper : objectMappers) {
|
||||
if (objectMapper.nested().isNested()) {
|
||||
return objectMapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ObjectMapper objectMapper : objectMappers) {
|
||||
if (objectMapper.nested().isNested()) {
|
||||
return objectMapper;
|
||||
}
|
||||
indexOf = objectPath.lastIndexOf('.');
|
||||
} while (indexOf != -1);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -714,6 +714,9 @@ public class SimpleNestedTests extends AbstractNodesTests {
|
|||
.startObject("child")
|
||||
.field("filter", true)
|
||||
.field("child_values", 1l)
|
||||
.startObject("child_obj")
|
||||
.field("value", 1l)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("child")
|
||||
.field("filter", false)
|
||||
|
@ -742,6 +745,9 @@ public class SimpleNestedTests extends AbstractNodesTests {
|
|||
.startObject("child")
|
||||
.field("filter", true)
|
||||
.field("child_values", 2l)
|
||||
.startObject("child_obj")
|
||||
.field("value", 2l)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("child")
|
||||
.field("filter", false)
|
||||
|
@ -770,6 +776,9 @@ public class SimpleNestedTests extends AbstractNodesTests {
|
|||
.startObject("child")
|
||||
.field("filter", true)
|
||||
.field("child_values", 3l)
|
||||
.startObject("child_obj")
|
||||
.field("value", 3l)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("child")
|
||||
.field("filter", false)
|
||||
|
@ -884,6 +893,24 @@ public class SimpleNestedTests extends AbstractNodesTests {
|
|||
// assertThat(searchResponse.getHits().getHits()[1].sortValues()[0].toString(), equalTo("-2"));
|
||||
// assertThat(searchResponse.getHits().getHits()[2].getId(), equalTo("1"));
|
||||
// assertThat(searchResponse.getHits().getHits()[2].sortValues()[0].toString(), equalTo("-1"));
|
||||
|
||||
// Check if closest nested type is resolved
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addSort(
|
||||
SortBuilders.fieldSort("parent.child.child_obj.value")
|
||||
.setNestedFilter(FilterBuilders.termFilter("parent.child.filter", true))
|
||||
.order(SortOrder.ASC)
|
||||
)
|
||||
.execute().actionGet();
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.getHits().getHits().length, equalTo(3));
|
||||
assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("1"));
|
||||
assertThat(searchResponse.getHits().getHits()[0].sortValues()[0].toString(), equalTo("1"));
|
||||
assertThat(searchResponse.getHits().getHits()[1].getId(), equalTo("2"));
|
||||
assertThat(searchResponse.getHits().getHits()[1].sortValues()[0].toString(), equalTo("2"));
|
||||
assertThat(searchResponse.getHits().getHits()[2].getId(), equalTo("3"));
|
||||
assertThat(searchResponse.getHits().getHits()[2].sortValues()[0].toString(), equalTo("3"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue