Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildcard field - add support for custom null values #57047

Merged
merged 1 commit into from
May 26, 2020
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 @@ -14,12 +14,16 @@ setup:
properties:
my_wildcard:
type: wildcard
null_wildcard:
type: wildcard
null_value: BLANK
- do:
index:
index: test-index
id: 1
body:
my_wildcard: hello world
null_wildcard: null
- do:
index:
index: test-index
Expand All @@ -32,6 +36,7 @@ setup:
id: 3
body:
my_wildcard: cAsE iNsEnSiTiVe World
null_wildcard: HAS_VALUE

- do:
indices.refresh: {}
Expand Down Expand Up @@ -101,6 +106,19 @@ setup:

- match: {hits.total.value: 1}

---
"null query":
- do:
search:
body:
track_total_hits: true
query:
wildcard:
null_wildcard: {value: "*BLANK*" }


- match: {hits.total.value: 1}

---
"Short suffix query":
- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ public static class Defaults {
FIELD_TYPE.freeze();
}
public static final int IGNORE_ABOVE = Integer.MAX_VALUE;
public static final String NULL_VALUE = null;
}

public static class Builder extends FieldMapper.Builder<Builder> {
protected int ignoreAbove = Defaults.IGNORE_ABOVE;

protected String nullValue = Defaults.NULL_VALUE;

public Builder(String name) {
super(name, Defaults.FIELD_TYPE, Defaults.FIELD_TYPE);
Expand Down Expand Up @@ -188,7 +189,13 @@ public Mapper.Builder<?> parse(String name, Map<String, Object> node, ParserCont
Map.Entry<String, Object> entry = iterator.next();
String propName = entry.getKey();
Object propNode = entry.getValue();
if (propName.equals("ignore_above")) {
if (propName.equals("null_value")) {
if (propNode == null) {
throw new MapperParsingException("Property [null_value] cannot be null.");
}
builder.nullValue(propNode.toString());
iterator.remove();
} else if (propName.equals("ignore_above")) {
builder.ignoreAbove(XContentMapValues.nodeIntegerValue(propNode, -1));
iterator.remove();
}
Expand Down Expand Up @@ -526,6 +533,9 @@ public WildcardFieldType fieldType() {
@Override
protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException {
super.doXContentBody(builder, includeDefaults, params);
if (includeDefaults || fieldType().nullValue() != null) {
builder.field("null_value", fieldType().nullValue());
}
if (includeDefaults || ignoreAbove != Defaults.IGNORE_ABOVE) {
builder.field("ignore_above", ignoreAbove);
}
Expand Down