Skip to content

Conversation

@nilabhsagar
Copy link
Contributor

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
Copy link
Collaborator

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?

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

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

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

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

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

@nilabhsagar
Copy link
Contributor Author

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

@nilabhsagar
Copy link
Contributor Author

@nik9000 changes done. Please verify

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

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

@nik9000
Copy link
Member

nik9000 commented Apr 24, 2017

elasticmachine, test this please.

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

nik9000 commented Apr 24, 2017

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

@nilabhsagar
Copy link
Contributor Author

Thanks @nik9000!

nik9000 pushed a commit that referenced this pull request Apr 24, 2017
…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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants