mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-28 10:58:30 +00:00
Revert "Do NOT allow termvectors on nested fields (#32728)"
This reverts commit fdff8f3db0093fa15cfa161f7dec80b715a48a43.
This commit is contained in:
parent
7e5efad929
commit
6f1ee76443
docs/reference/docs
rest-api-spec/src/main/resources/rest-api-spec/test/termvectors
server/src/main/java/org/elasticsearch/index/termvectors
@ -30,10 +30,6 @@ in similar way to the <<query-dsl-multi-match-query,multi match query>>
|
|||||||
[WARNING]
|
[WARNING]
|
||||||
Note that the usage of `/_termvector` is deprecated in 2.0, and replaced by `/_termvectors`.
|
Note that the usage of `/_termvector` is deprecated in 2.0, and replaced by `/_termvectors`.
|
||||||
|
|
||||||
[WARNING]
|
|
||||||
Term Vectors API doesn't work on nested fields. `/_termvectors` on a nested
|
|
||||||
field and any sub-fields of a nested field returns empty results.
|
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
=== Return values
|
=== Return values
|
||||||
|
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
setup:
|
|
||||||
- do:
|
|
||||||
indices.create:
|
|
||||||
index: testidx
|
|
||||||
body:
|
|
||||||
mappings:
|
|
||||||
_doc:
|
|
||||||
properties:
|
|
||||||
nested1:
|
|
||||||
type : nested
|
|
||||||
properties:
|
|
||||||
nested1-text:
|
|
||||||
type: text
|
|
||||||
object1:
|
|
||||||
properties:
|
|
||||||
object1-text:
|
|
||||||
type: text
|
|
||||||
object1-nested1:
|
|
||||||
type: nested
|
|
||||||
properties:
|
|
||||||
object1-nested1-text:
|
|
||||||
type: text
|
|
||||||
- do:
|
|
||||||
index:
|
|
||||||
index: testidx
|
|
||||||
type: _doc
|
|
||||||
id: 1
|
|
||||||
body:
|
|
||||||
"nested1" : [{ "nested1-text": "text1" }]
|
|
||||||
"object1" : [{ "object1-text": "text2" }, "object1-nested1" : [{"object1-nested1-text" : "text3"}]]
|
|
||||||
|
|
||||||
- do:
|
|
||||||
indices.refresh: {}
|
|
||||||
|
|
||||||
---
|
|
||||||
"Termvectors on nested fields should return empty results":
|
|
||||||
|
|
||||||
- do:
|
|
||||||
termvectors:
|
|
||||||
index: testidx
|
|
||||||
type: _doc
|
|
||||||
id: 1
|
|
||||||
fields: ["nested1", "nested1.nested1-text", "object1.object1-nested1", "object1.object1-nested1.object1-nested1-text", "object1.object1-text"]
|
|
||||||
|
|
||||||
- is_false: term_vectors.nested1
|
|
||||||
- is_false: term_vectors.nested1\.nested1-text # escaping as the field name contains dot
|
|
||||||
- is_false: term_vectors.object1\.object1-nested1
|
|
||||||
- is_false: term_vectors.object1\.object1-nested1\.object1-nested1-text
|
|
||||||
- is_true: term_vectors.object1\.object1-text
|
|
@ -45,7 +45,6 @@ import org.elasticsearch.index.mapper.DocumentMapperForType;
|
|||||||
import org.elasticsearch.index.mapper.KeywordFieldMapper;
|
import org.elasticsearch.index.mapper.KeywordFieldMapper;
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.mapper.ObjectMapper;
|
|
||||||
import org.elasticsearch.index.mapper.ParseContext;
|
import org.elasticsearch.index.mapper.ParseContext;
|
||||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||||
import org.elasticsearch.index.mapper.SourceFieldMapper;
|
import org.elasticsearch.index.mapper.SourceFieldMapper;
|
||||||
@ -161,7 +160,7 @@ public class TermVectorsService {
|
|||||||
request.selectedFields(fieldNames.toArray(Strings.EMPTY_ARRAY));
|
request.selectedFields(fieldNames.toArray(Strings.EMPTY_ARRAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isValidField(MappedFieldType fieldType, IndexShard indexShard) {
|
private static boolean isValidField(MappedFieldType fieldType) {
|
||||||
// must be a string
|
// must be a string
|
||||||
if (fieldType instanceof StringFieldType == false) {
|
if (fieldType instanceof StringFieldType == false) {
|
||||||
return false;
|
return false;
|
||||||
@ -170,16 +169,6 @@ public class TermVectorsService {
|
|||||||
if (fieldType.indexOptions() == IndexOptions.NONE) {
|
if (fieldType.indexOptions() == IndexOptions.NONE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// and must not be under nested field
|
|
||||||
int dotIndex = fieldType.name().indexOf('.');
|
|
||||||
while (dotIndex > -1) {
|
|
||||||
String parentField = fieldType.name().substring(0, dotIndex);
|
|
||||||
ObjectMapper mapper = indexShard.mapperService().getObjectMapper(parentField);
|
|
||||||
if (mapper != null && mapper.nested().isNested()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
dotIndex = fieldType.name().indexOf('.', dotIndex + 1);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +177,7 @@ public class TermVectorsService {
|
|||||||
Set<String> validFields = new HashSet<>();
|
Set<String> validFields = new HashSet<>();
|
||||||
for (String field : selectedFields) {
|
for (String field : selectedFields) {
|
||||||
MappedFieldType fieldType = indexShard.mapperService().fullName(field);
|
MappedFieldType fieldType = indexShard.mapperService().fullName(field);
|
||||||
if (isValidField(fieldType, indexShard) == false) {
|
if (!isValidField(fieldType)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// already retrieved, only if the analyzer hasn't been overridden at the field
|
// already retrieved, only if the analyzer hasn't been overridden at the field
|
||||||
@ -295,7 +284,7 @@ public class TermVectorsService {
|
|||||||
Collection<DocumentField> documentFields = new HashSet<>();
|
Collection<DocumentField> documentFields = new HashSet<>();
|
||||||
for (IndexableField field : doc.getFields()) {
|
for (IndexableField field : doc.getFields()) {
|
||||||
MappedFieldType fieldType = indexShard.mapperService().fullName(field.name());
|
MappedFieldType fieldType = indexShard.mapperService().fullName(field.name());
|
||||||
if (isValidField(fieldType, indexShard) == false) {
|
if (!isValidField(fieldType)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (request.selectedFields() != null && !request.selectedFields().contains(field.name())) {
|
if (request.selectedFields() != null && !request.selectedFields().contains(field.name())) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user