Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import org.elasticsearch.xcontent.XContentParser.Token;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
* A {@link FieldMapper} that exposes Lucene's {@link FeatureField}.
Expand Down Expand Up @@ -152,12 +154,13 @@ public ValueFetcher valueFetcher(SearchExecutionContext context, String format)
if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}
return new SourceValueFetcher(name(), context) {
return sourceValueFetcher(context.isSourceEnabled() ? context.sourcePath(name()) : Collections.emptySet());
}

private SourceValueFetcher sourceValueFetcher(Set<String> sourcePaths) {
return new SourceValueFetcher(sourcePaths, nullValue) {
@Override
protected Float parseSourceValue(Object value) {
if (value.equals("")) {
return nullValue;
}
protected Object parseSourceValue(Object value) {
return objectToFloat(value);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public void testFetchSourceValue() throws IOException {

assertEquals(List.of(3.14f), fetchSourceValue(mapper, 3.14));
assertEquals(List.of(42.9f), fetchSourceValue(mapper, "42.9"));
assertEquals(List.of(2.0f), fetchSourceValue(mapper, ""));
assertEquals(List.of(2.0f), fetchSourceValue(mapper, null));
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
"Non positive null_vallue":
"Non positive null_value":

- skip:
version: " - 8.8.99"
reason: "null_value parameter was added in 8.9.0"

- do:
catch: bad_request
catch: /\[null_value\] must be a positive normal float for field of type \[rank_feature\]/
indices.create:
index: test2
body:
Expand All @@ -16,7 +16,7 @@
properties:
pagerank:
type: rank_feature
null_vallue: -3
null_value: -3

---
"Search rank_feature with and without null_value":
Expand All @@ -35,7 +35,7 @@
properties:
pagerank:
type: rank_feature
null_value: 15
null_value: 100
url_length:
type: rank_feature

Expand All @@ -55,9 +55,19 @@
pagerank: null
url_length: null

# can't index a field value equal to an empty string
- do:
catch: /failed to parse field \[pagerank\] of type \[rank_feature\] in document/
index:
index: test1
id: "wrong_document1"
body:
pagerank: ""

- do:
indices.refresh: {}

# docs with null values are absent in search results
- do:
search:
index: test1
Expand All @@ -72,13 +82,17 @@
- match:
hits.hits.0._id: "1"

# docs with null values are present in search results
- do:
search:
index: test1
body:
query:
rank_feature:
field: pagerank
fields:
- field: 'pagerank'
- field: 'url_length'

- match:
hits.total.value: 2
Expand All @@ -88,3 +102,8 @@

- match:
hits.hits.1._id: "1"

- match: { hits.hits.0._source.pagerank: null }
- match: { hits.hits.0.fields.pagerank.0: 100 }
- match: { hits.hits.0._source.url_length: null }
- is_false: hits.hits.0.fields.url_length