Skip to content

Use typed_keys parameter to prefix suggester names by type in search responses#23080

Merged
tlrx merged 2 commits intoelastic:masterfrom
tlrx:prefix-suggester-names-by-types
Feb 10, 2017
Merged

Use typed_keys parameter to prefix suggester names by type in search responses#23080
tlrx merged 2 commits intoelastic:masterfrom
tlrx:prefix-suggester-names-by-types

Conversation

@tlrx
Copy link
Copy Markdown
Member

@tlrx tlrx commented Feb 9, 2017

This pull request reuses the typed_keys parameter added in #22965, but this time it applies it to suggesters. When set to true, the suggester names in the search response will be prefixed with a prefix that reflects their type.

This pull request adds a new parameter to the REST Search API named `prefixed_name`. When set to true, the suggester names in the search response will be prefixed with a prefix that reflects their type.
Copy link
Copy Markdown
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

@tlrx thanks, this looks great I think. Left a small idea but feel free to disregard


private static final Set<String> RESPONSE_PARAMS = Collections.singleton("typed_keys");
public static final String TYPED_KEYS_PARAM = "typed_keys";
private static final Set<String> RESPONSE_PARAMS = Collections.singleton(TYPED_KEYS_PARAM);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 I like this here

builder.startArray(name);
if (params.paramAsBoolean(RestSearchAction.TYPED_KEYS_PARAM, false)) {
// Concatenates the type and the name of the aggregation (ex: top_hits#foo)
builder.startArray(String.join(InternalAggregation.TYPED_KEYS_DELIMITER, getType(), getName()));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a thought: maybe instead of referring to the Delimiter in Aggregations we can have an own constant in Suggest and either declare the same symbol there or delegate to InternalAggregation.TYPED_KEYS_DELIMITER? The delimiter doesn't need to be the same in aggs and suggestions, only the parsing part needs to refer to it (although its good to have the same like we do now I think)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why would we want to use the same parameter but not the same delimiter? aren't we making things more complicated than they are?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks @cbuescher but I feel like this will complicates things, I prefer to leave it as it is.

@@ -0,0 +1,84 @@
[[returning-suggesters-type]]
=== Returning the type of the suggester
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

At first I was wondering if we should document this parameter since it is only for internal use, but then I saw you also did this for aggregations, so I agree it might be useful for anybody who needs to parse the response.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I think it is still useful to document it correctly, that might be useful for others clients too.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This has had me stuck for a day, as to why my aggs all of a sudden had a prefix to the name. Is there a way to disable?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is concerning, this change was backwards compatible meaning that typed_keys defaults to false, and only the java high-level REST client enables them. Can you describe what you have experienced?

@clintongormley
Copy link
Copy Markdown
Contributor

In the description you say "suggester names", but it affect agg names too, no?

@tlrx
Copy link
Copy Markdown
Member Author

tlrx commented Feb 9, 2017

@clintongormley We added the typed_keys parameter support for aggregation in #22965, which is already merged. This PR is for the same thing for Suggesters.

@javanna
Copy link
Copy Markdown
Contributor

javanna commented Feb 9, 2017

@clintongormley @tlrx I think what is confusing in the title here is that the parameter is not "added". it is just applied to suggestions too in the search response.

Copy link
Copy Markdown
Contributor

@javanna javanna 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 a lot @tlrx !!!

@tlrx tlrx changed the title Add parameter to prefix suggester name by type in search responses Use typed_keys parameter to prefix suggester names by type in search responses Feb 10, 2017
@tlrx tlrx merged commit e2e5937 into elastic:master Feb 10, 2017
@tlrx tlrx deleted the prefix-suggester-names-by-types branch February 10, 2017 10:35
tlrx added a commit that referenced this pull request Feb 10, 2017
…h responses (#23080)

Thiscommit reuses the typed_keys parameter added in #22965, but this time it applies it to suggesters. When set to true, the suggester names in the search response will be prefixed with a prefix that reflects their type.
@tlrx
Copy link
Copy Markdown
Member Author

tlrx commented Feb 10, 2017

Thanks @javanna @cbuescher !

I updated the description and the title of the PR/commit.

@tlrx tlrx removed the review label Feb 10, 2017
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Feb 10, 2017
* master:
  Cleanup RestGetAliasesAction.java
  Use `typed_keys` parameter to prefix suggester names by type in search responses (elastic#23080)
  [Docs] Remove unnecessary // TEST[continued] in search-template doc
@sqlboy
Copy link
Copy Markdown

sqlboy commented Jul 10, 2018

Is there a way to disable typed keys?

@tlrx
Copy link
Copy Markdown
Member Author

tlrx commented Jul 10, 2018

@sqlboy Suggesters names are only prefixed by their types when the typed_keys parameter is set to true. So if you want to disable typed keys you should not pass this parameter at all or set it to falsewhen executing the requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants