Add version support for inner hits in field collapsing
This commit is contained in:
parent
e542c03bea
commit
f5e0932c8d
|
@ -165,6 +165,7 @@ final class ExpandSearchPhase extends SearchPhase {
|
||||||
}
|
}
|
||||||
groupSource.explain(options.isExplain());
|
groupSource.explain(options.isExplain());
|
||||||
groupSource.trackScores(options.isTrackScores());
|
groupSource.trackScores(options.isTrackScores());
|
||||||
|
groupSource.version(options.isVersion());
|
||||||
return groupSource;
|
return groupSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.elasticsearch.action.search;
|
package org.elasticsearch.action.search;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.support.IndicesOptions;
|
|
||||||
import org.elasticsearch.common.document.DocumentField;
|
import org.elasticsearch.common.document.DocumentField;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.text.Text;
|
import org.elasticsearch.common.text.Text;
|
||||||
|
@ -248,6 +247,8 @@ public class ExpandSearchPhaseTests extends ESTestCase {
|
||||||
|
|
||||||
public void testExpandRequestOptions() throws IOException {
|
public void testExpandRequestOptions() throws IOException {
|
||||||
MockSearchPhaseContext mockSearchPhaseContext = new MockSearchPhaseContext(1);
|
MockSearchPhaseContext mockSearchPhaseContext = new MockSearchPhaseContext(1);
|
||||||
|
boolean version = randomBoolean();
|
||||||
|
|
||||||
mockSearchPhaseContext.searchTransport = new SearchTransportService(
|
mockSearchPhaseContext.searchTransport = new SearchTransportService(
|
||||||
Settings.builder().put("search.remote.connect", false).build(), null, null) {
|
Settings.builder().put("search.remote.connect", false).build(), null, null) {
|
||||||
|
|
||||||
|
@ -256,13 +257,14 @@ public class ExpandSearchPhaseTests extends ESTestCase {
|
||||||
final QueryBuilder postFilter = QueryBuilders.existsQuery("foo");
|
final QueryBuilder postFilter = QueryBuilders.existsQuery("foo");
|
||||||
assertTrue(request.requests().stream().allMatch((r) -> "foo".equals(r.preference())));
|
assertTrue(request.requests().stream().allMatch((r) -> "foo".equals(r.preference())));
|
||||||
assertTrue(request.requests().stream().allMatch((r) -> "baz".equals(r.routing())));
|
assertTrue(request.requests().stream().allMatch((r) -> "baz".equals(r.routing())));
|
||||||
|
assertTrue(request.requests().stream().allMatch((r) -> version == r.source().version()));
|
||||||
assertTrue(request.requests().stream().allMatch((r) -> postFilter.equals(r.source().postFilter())));
|
assertTrue(request.requests().stream().allMatch((r) -> postFilter.equals(r.source().postFilter())));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mockSearchPhaseContext.getRequest().source(new SearchSourceBuilder()
|
mockSearchPhaseContext.getRequest().source(new SearchSourceBuilder()
|
||||||
.collapse(
|
.collapse(
|
||||||
new CollapseBuilder("someField")
|
new CollapseBuilder("someField")
|
||||||
.setInnerHits(new InnerHitBuilder().setName("foobarbaz"))
|
.setInnerHits(new InnerHitBuilder().setName("foobarbaz").setVersion(version))
|
||||||
)
|
)
|
||||||
.postFilter(QueryBuilders.existsQuery("foo")))
|
.postFilter(QueryBuilders.existsQuery("foo")))
|
||||||
.preference("foobar")
|
.preference("foobar")
|
||||||
|
|
|
@ -7,36 +7,48 @@ setup:
|
||||||
index: test
|
index: test
|
||||||
type: test
|
type: test
|
||||||
id: 1
|
id: 1
|
||||||
|
version_type: external
|
||||||
|
version: 11
|
||||||
body: { numeric_group: 1, sort: 10 }
|
body: { numeric_group: 1, sort: 10 }
|
||||||
- do:
|
- do:
|
||||||
index:
|
index:
|
||||||
index: test
|
index: test
|
||||||
type: test
|
type: test
|
||||||
id: 2
|
id: 2
|
||||||
|
version_type: external
|
||||||
|
version: 22
|
||||||
body: { numeric_group: 1, sort: 6 }
|
body: { numeric_group: 1, sort: 6 }
|
||||||
- do:
|
- do:
|
||||||
index:
|
index:
|
||||||
index: test
|
index: test
|
||||||
type: test
|
type: test
|
||||||
id: 3
|
id: 3
|
||||||
|
version_type: external
|
||||||
|
version: 33
|
||||||
body: { numeric_group: 1, sort: 24 }
|
body: { numeric_group: 1, sort: 24 }
|
||||||
- do:
|
- do:
|
||||||
index:
|
index:
|
||||||
index: test
|
index: test
|
||||||
type: test
|
type: test
|
||||||
id: 4
|
id: 4
|
||||||
|
version_type: external
|
||||||
|
version: 44
|
||||||
body: { numeric_group: 25, sort: 10 }
|
body: { numeric_group: 25, sort: 10 }
|
||||||
- do:
|
- do:
|
||||||
index:
|
index:
|
||||||
index: test
|
index: test
|
||||||
type: test
|
type: test
|
||||||
id: 5
|
id: 5
|
||||||
|
version_type: external
|
||||||
|
version: 55
|
||||||
body: { numeric_group: 25, sort: 5 }
|
body: { numeric_group: 25, sort: 5 }
|
||||||
- do:
|
- do:
|
||||||
index:
|
index:
|
||||||
index: test
|
index: test
|
||||||
type: test
|
type: test
|
||||||
id: 6
|
id: 6
|
||||||
|
version_type: external
|
||||||
|
version: 66
|
||||||
body: { numeric_group: 3, sort: 36 }
|
body: { numeric_group: 3, sort: 36 }
|
||||||
- do:
|
- do:
|
||||||
indices.refresh:
|
indices.refresh:
|
||||||
|
@ -322,3 +334,56 @@ setup:
|
||||||
- match: { hits.hits.2.inner_hits.sub_hits_desc.hits.total: 2 }
|
- match: { hits.hits.2.inner_hits.sub_hits_desc.hits.total: 2 }
|
||||||
- length: { hits.hits.2.inner_hits.sub_hits_desc.hits.hits: 1 }
|
- length: { hits.hits.2.inner_hits.sub_hits_desc.hits.hits: 1 }
|
||||||
- match: { hits.hits.2.inner_hits.sub_hits_desc.hits.hits.0._id: "4" }
|
- match: { hits.hits.2.inner_hits.sub_hits_desc.hits.hits.0._id: "4" }
|
||||||
|
|
||||||
|
---
|
||||||
|
"field collapsing, inner_hits and version":
|
||||||
|
|
||||||
|
- skip:
|
||||||
|
version: " - 6.99.99"
|
||||||
|
reason: "bug fixed in 7.0.0"
|
||||||
|
|
||||||
|
- do:
|
||||||
|
search:
|
||||||
|
index: test
|
||||||
|
type: test
|
||||||
|
body:
|
||||||
|
collapse: { field: numeric_group, inner_hits: { name: sub_hits, version: true, size: 2, sort: [{ sort: asc }] } }
|
||||||
|
sort: [{ sort: desc }]
|
||||||
|
version: true
|
||||||
|
|
||||||
|
- match: { hits.total: 6 }
|
||||||
|
- length: { hits.hits: 3 }
|
||||||
|
- match: { hits.hits.0._index: test }
|
||||||
|
- match: { hits.hits.0._type: test }
|
||||||
|
- match: { hits.hits.0.fields.numeric_group: [3] }
|
||||||
|
- match: { hits.hits.0.sort: [36] }
|
||||||
|
- match: { hits.hits.0._id: "6" }
|
||||||
|
- match: { hits.hits.0._version: 66 }
|
||||||
|
- match: { hits.hits.0.inner_hits.sub_hits.hits.total: 1 }
|
||||||
|
- length: { hits.hits.0.inner_hits.sub_hits.hits.hits: 1 }
|
||||||
|
- match: { hits.hits.0.inner_hits.sub_hits.hits.hits.0._id: "6" }
|
||||||
|
- match: { hits.hits.0.inner_hits.sub_hits.hits.hits.0._version: 66 }
|
||||||
|
- match: { hits.hits.1._index: test }
|
||||||
|
- match: { hits.hits.1._type: test }
|
||||||
|
- match: { hits.hits.1.fields.numeric_group: [1] }
|
||||||
|
- match: { hits.hits.1.sort: [24] }
|
||||||
|
- match: { hits.hits.1._id: "3" }
|
||||||
|
- match: { hits.hits.1._version: 33 }
|
||||||
|
- match: { hits.hits.1.inner_hits.sub_hits.hits.total: 3 }
|
||||||
|
- length: { hits.hits.1.inner_hits.sub_hits.hits.hits: 2 }
|
||||||
|
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._id: "2" }
|
||||||
|
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._version: 22 }
|
||||||
|
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._id: "1" }
|
||||||
|
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._version: 11 }
|
||||||
|
- match: { hits.hits.2._index: test }
|
||||||
|
- match: { hits.hits.2._type: test }
|
||||||
|
- match: { hits.hits.2.fields.numeric_group: [25] }
|
||||||
|
- match: { hits.hits.2.sort: [10] }
|
||||||
|
- match: { hits.hits.2._id: "4" }
|
||||||
|
- match: { hits.hits.2._version: 44 }
|
||||||
|
- match: { hits.hits.2.inner_hits.sub_hits.hits.total: 2 }
|
||||||
|
- length: { hits.hits.2.inner_hits.sub_hits.hits.hits: 2 }
|
||||||
|
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._id: "5" }
|
||||||
|
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._version: 55 }
|
||||||
|
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._id: "4" }
|
||||||
|
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.1._version: 44 }
|
||||||
|
|
Loading…
Reference in New Issue