Skip to content

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

Merged

Conversation

pgomulka
Copy link
Contributor

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

  • Have you signed the contributor license agreement?
  • Have you followed the contributor guidelines?
  • If submitting code, have you built your formula locally prior to submission with gradle check?
  • If submitting code, is your pull request against master? Unless there is a good reason otherwise, we prefer pull requests against master and will backport as needed.
  • If submitting code, have you checked that your submission is for an OS that we support?
  • If you are submitting this code for a class then read our policy for that.

@pgomulka pgomulka requested a review from jimczi September 26, 2018 13:02
@pgomulka pgomulka force-pushed the fix/15115-support-completion-multi-fields branch from 107d745 to 59f7bca Compare September 26, 2018 13:11
@jimczi jimczi added >enhancement :Search Relevance/Suggesters "Did you mean" and suggestions as you type v7.0.0 v6.5.0 labels Sep 26, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

Copy link
Contributor

@jimczi jimczi left a 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();
Copy link
Contributor

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));
  }...

Copy link
Contributor Author

@pgomulka pgomulka Sep 27, 2018

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));
}

Copy link
Contributor

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.

Copy link
Contributor Author

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

@pgomulka
Copy link
Contributor Author

retest this please

@pgomulka pgomulka force-pushed the fix/15115-support-completion-multi-fields branch from 17ad68d to 55a72b5 Compare September 27, 2018 18:05
@pgomulka
Copy link
Contributor Author

pgomulka commented Oct 1, 2018

@jimczi I have updated the PR, could you please take a look?

Copy link
Contributor

@jimczi jimczi left a 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));
Copy link
Contributor

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));

?

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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));
Copy link
Contributor

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));
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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));
Copy link
Contributor

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));
Copy link
Contributor

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));
Copy link
Contributor

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
@pgomulka pgomulka force-pushed the fix/15115-support-completion-multi-fields branch 5 times, most recently from a795fd7 to 3bf447e Compare October 1, 2018 16:26
@pgomulka pgomulka force-pushed the fix/15115-support-completion-multi-fields branch from 3bf447e to e683594 Compare October 1, 2018 17:35
@pgomulka pgomulka force-pushed the fix/15115-support-completion-multi-fields branch from 40f868b to b3be7e0 Compare October 2, 2018 09:06
@pgomulka
Copy link
Contributor Author

pgomulka commented Oct 2, 2018

@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?

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @pgomulka

@pgomulka pgomulka merged commit 3f8cc89 into elastic:master Oct 2, 2018
@pgomulka
Copy link
Contributor Author

pgomulka commented Oct 2, 2018

Thank you @jimczi

@pgomulka
Copy link
Contributor Author

pgomulka commented Oct 2, 2018

going to back port to v6.5.0

pgomulka added a commit to pgomulka/elasticsearch that referenced this pull request Oct 2, 2018
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
pgomulka added a commit to pgomulka/elasticsearch that referenced this pull request Oct 2, 2018
pgomulka added a commit that referenced this pull request Oct 3, 2018
)

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
kcm pushed a commit that referenced this pull request Oct 30, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Indexing completion type fields with multi-fields fails
4 participants