-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Completion types with multi-fields support #34081
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
Completion types with multi-fields support #34081
Conversation
107d745
to
59f7bca
Compare
Pinging @elastic/es-search-aggs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pgomulka , it's a good start. I left some comments.
// ignore null values | ||
if (token == Token.VALUE_NULL) { | ||
if (context.externalValueSet()) { | ||
inputMap = (Map<String, CompletionInputMetaData>) context.externalValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The external value is not always set by another completion
mapper so you need to check the type.
I think it would be simpler to just add an input field in the CompletionInputMetaData
class and do something like:
if (context.externalValueSet()) {
if (context.externalValue().getClass().equals(CompletionInputMetaData.class)) {
CompletionInputMetaData inputAndMeta = (CompletionInputMetaData) context.externalValue();
inputMap = Collections.singletonMap(inputAndMeta.input(), inputAndMeta);
} else {
inputMap = Collections.singletonMap(context.externalValue().toString(), new CompletionInputMetaData(Collections.<String, Set<CharSequence>>emptyMap(), 1));
}...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well spotted, indeed missed these scenarios where external value is set by GeoPointFIeldMapper. Will add test cases and cover that.
good suggestion. Will extend CompletionInputMetaData to include inputField and return that as a toString
assertSuggestFields(indexableFields.getFields("completion"), 1); | ||
assertThat(indexableFields.getFields("completion.analyzed"), arrayWithSize(2)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a test with a context completion suggester as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, will add additional test cases to cover that
retest this please |
17ad68d
to
55a72b5
Compare
@jimczi I have updated the PR, could you please take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good @pgomulka . I left some comments regarding the tests.
inputMap = Collections.singletonMap(inputAndMeta.inputField, inputAndMeta); | ||
} else { | ||
String fieldName = context.externalValue().toString(); | ||
inputMap = Collections.singletonMap(fieldName, new CompletionInputMetaData(fieldName, Collections.<String, Set<CharSequence>>emptyMap(), 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify this line with:
inputMap = Collections.singletonMap(fieldName, new CompletionInputMetaData(fieldName, Collections.emptyMap(), 1));
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely, will simplify another place in that file to use jdk8 type inference as well
@@ -570,13 +593,20 @@ private void parse(ParseContext parseContext, Token token, XContentParser parser | |||
} | |||
|
|||
static class CompletionInputMetaData { | |||
public final String inputField; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe input
, inputField
is misleading I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good suggestion, this contains the actual value of the input field, so should be more clear
|
||
ParseContext.Document indexableFields = parsedDocument.rootDoc(); | ||
assertSuggestFields(indexableFields.getFields("completion"), 1); | ||
assertThat(indexableFields.getFields("completion.analyzed"), arrayWithSize(2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that the field has the expected content?:
assertEquals("suggestion", indexableFields.getFields("completion.analyzed")[0].stringValue());
XContentType.JSON)); | ||
|
||
ParseContext.Document indexableFields = parsedDocument.rootDoc(); | ||
assertThat(indexableFields.getFields("keywordfield"), arrayWithSize(6)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that the field has the expected content?
|
||
ParseContext.Document indexableFields = parsedDocument.rootDoc(); | ||
assertFieldsOfType(indexableFields.getFields("suggest"), ContextSuggestField.class, 2); | ||
assertFieldsOfType(indexableFields.getFields("suggest.subsuggest"), ContextSuggestField.class, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that the field has the expected content?:
|
||
ParseContext.Document indexableFields = parsedDocument.rootDoc(); | ||
assertFieldsOfType(indexableFields.getFields("suggest"), ContextSuggestField.class, 2); | ||
assertFieldsOfType(indexableFields.getFields("suggest.subsuggest"), ContextSuggestField.class, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that the field has the expected content?:
|
||
ParseContext.Document indexableFields = parsedDocument.rootDoc(); | ||
assertThat(indexableFields.getFields("geofield"), arrayWithSize(2)); | ||
assertSuggestFields(indexableFields.getFields("geofield.analyzed"), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that the field has the expected content?:
|
||
ParseContext.Document indexableFields = parsedDocument.rootDoc(); | ||
assertSuggestFields(indexableFields.getFields("completion"), 1); | ||
assertThat(indexableFields.getFields("completion.analyzed"), arrayWithSize(1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that the field has the expected content?:
|
||
ParseContext.Document indexableFields = parsedDocument.rootDoc(); | ||
assertSuggestFields(indexableFields.getFields("completion"), 2); | ||
assertThat(indexableFields.getFields("completion.analyzed"), arrayWithSize(2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that the field has the expected content?:
|
||
ParseContext.Document indexableFields = parsedDocument.rootDoc(); | ||
assertSuggestFields(indexableFields.getFields("completion"), 2); | ||
assertThat(indexableFields.getFields("completion.analyzed"), arrayWithSize(4)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that the field has the expected content?:
Mappings with completion type and multi-fields, were not able to index array or object format on completion fields. Only string format was supproted. This is fixed by providing multiField parser with externalValueContext with already parsed object closes elastic#15115
refactor to reuse CompletionInputMetaData in externalValue Context add test cases with context completion
a795fd7
to
3bf447e
Compare
3bf447e
to
e683594
Compare
40f868b
to
b3be7e0
Compare
@jimczi updated the tests and added an additional REST test cover scenarios I couldn't test in a junit test. Can you please have a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @pgomulka
Thank you @jimczi |
going to back port to v6.5.0 |
Mappings with completion type and multi-fields, were not able to index array or object format on completion fields. Only string format was supported. This is fixed by providing multiField parser with externalValueContext with already parsed object closes elastic#15115
) Mappings with completion type and multi-fields, were not able to index array or object format on completion fields. Only string format was supported. This is fixed by providing multiField parser with externalValueContext with already parsed object * Adapt test after backport of #34081 closes #15115
Mappings with completion type and multi-fields, were not able to index array or object format on completion fields. Only string format was supported. This is fixed by providing multiField parser with externalValueContext with already parsed object closes #15115
Mappings with completion type and multi-fields, were not able to index array or
object format on completion fields. Only string format was supproted.
This is fixed by providing multiField parser with externalValueContext with already parsed object
closes #15115
gradle check
?