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

Provide informative error message in case of unknown suggestion context. #24241

Merged
merged 2 commits into from Apr 24, 2017

Conversation

Projects
None yet
3 participants
@nilabhsagar
Contributor

nilabhsagar commented Apr 21, 2017

At present providing unknown context in a suggestion context query does not provide informative error message.
Consider below mapping and correspongding query

Mapping

{
    "mappings": {
        "products" : {
            "properties" : {
                "suggest" : {
                    "type" : "completion",
                    "contexts": [
                        { 
                            "name": "product_type",
                            "type": "category",
                            "path": "cat"
                        },
                        { 
                            "name": "product_color",
                            "type": "category",
                            "path": "cat"
                        },
                        { 
                            "name": "product_size",
                            "type": "category",
                            "path": "cat"
                        }
                    ]
                }
            }
        }
    }
}

Query

{
    "suggest": {
        "products_suggestion" : {
            "prefix" : "sho",
            "completion" : {
                "field" : "suggest",
                "size": 10,
                "contexts": {
                    "product_type": "casual",
                    "product_brand": "reebok"
                }
            }
        }
    }
}

Executing the above query will show error message as below

"Unknown context name[product_brand], must be one of 3"

This error message is not very informative as it only convey the number of context supported. However printing all the accepted contexts will be more informative, like below:

"Unknown context name[product_brand], must be one of [product_size, product_color, product_type]"

This pull request fixes the issue mentioned.

@elasticmachine

This comment has been minimized.

elasticmachine commented Apr 21, 2017

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@nik9000

I left a minor thing but it makes sense to me. If you'll make the change I can see about merging.

@@ -81,7 +81,7 @@ public int size() {
public ContextMapping get(String name) {
ContextMapping contextMapping = contextNameMap.get(name);
if (contextMapping == null) {
throw new IllegalArgumentException("Unknown context name[" + name + "], must be one of " + contextNameMap.size());
throw new IllegalArgumentException("Unknown context name[" + name + "], must be one of " + contextNameMap.keySet().toString());

This comment has been minimized.

@nik9000

nik9000 Apr 21, 2017

Contributor

I think we'd better sort the list of keys before adding it to the string so we get consistent error messages. This'll make testing much easier and be marginally easier on the eyes.

This comment has been minimized.

@nik9000

nik9000 Apr 21, 2017

Contributor

Can you add a space between "name" and "["?

@nilabhsagar

This comment has been minimized.

Contributor

nilabhsagar commented Apr 21, 2017

Thanks @nik9000 I agree, sorting will have consistent behaviour. I will do both the changes as suggested and commit.

@nilabhsagar

This comment has been minimized.

Contributor

nilabhsagar commented Apr 21, 2017

@nik9000 changes done. Please verify

@nik9000

Looks good to me. I'll work on getting this merged.

@nik9000

This comment has been minimized.

Contributor

nik9000 commented Apr 24, 2017

elasticmachine, test this please.

@nik9000 nik9000 merged commit 373edee into elastic:master Apr 24, 2017

2 checks passed

CLA Commit author has signed the CLA
Details
elasticsearch-ci Build finished.
Details
@nik9000

This comment has been minimized.

Contributor

nik9000 commented Apr 24, 2017

Thanks @nilabhsagar! I've merged to master and an backporting to 5.x.

@nilabhsagar

This comment has been minimized.

Contributor

nilabhsagar commented Apr 24, 2017

Thanks @nik9000!

nik9000 added a commit that referenced this pull request Apr 24, 2017

Provide informative error message in case of unknown suggestion conte…
…xt. (#24241)

Provide a list of available contexts when you send an unknown context to the completion suggester.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment