Skip to content
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

Query DSL: Bool query/filter to be valid JSON #6

Closed
kimchy opened this issue Feb 12, 2010 · 5 comments

Comments

@kimchy
Copy link
Member

commented Feb 12, 2010

Currently, the bool query is not a valid Javassctipt (still valid JSON though...) since indicating two must clauses uses the same field name for a JSON object. The old way should still be supported, but, we should also allow for something like this:

Currently, the bool query is not a valid Javassctipt (still valid JSON though...) since indicating two must clauses uses the same field name for a JSON object. The old way should still be supported, but, we should also allow for something like this:

{
    bool : {
        must : [
            {
                queryString : {
                    defaultField : "content",
                    query : "test1"
                }
            },
            {
                queryString : {
                    defaultField : "content",
                    query : "test4"
                }
            }
        ],
        mustNot: {
            queryString : {
                defaultField : "content",
                query : "test2"
            }
        },
        should: {
            queryString : {
                defaultField : "content",
                query : "test3"
            }
        }
    }
}
@simonw

This comment has been minimized.

Copy link
Contributor

commented Feb 12, 2010

It's definitely still invalid JSON - the JSON spec on http://www.json.org/ is clear that double quotes are required around string values, including object keys. In practice it's not a huge problem that elasticsearch accepts invalid JSON for the queries though, provided it also accepts valid JSON. The JSON output by elasticsearch uses quotes in the right places and is absolutely fine.

Python's JSON parser is strict by default, and throws the following exception if I feed in the above example:

ValueError: Expecting property name: line 2 column 5 (char 6)

@kimchy

This comment has been minimized.

Copy link
Member Author

commented Feb 12, 2010

The invalid part I was talking about is the usage of the same field name twice within an object.

Regarding the quotes on field names, you are absolutely correct. ES does accept field names that are either quoted or not, for two reasons:

  1. Less text on the wire / simplifies writing examples :).
  2. Makes direct Javascript usage simpler.
@clintongormley

This comment has been minimized.

Copy link
Member

commented Feb 19, 2010

Actually, non-unique key names are invalid JSON. See section 2.2 in http://www.ietf.org/rfc/rfc4627.txt?number=4627

So whenever you have repeatable items, you should provide both:
{ key: value }
{ keys: [ value_1, value_n ] }

@clintongormley

This comment has been minimized.

Copy link
Member

commented Feb 19, 2010

or:

{ key: value }  | { key: [ value_1, value_n] }
@kimchy

This comment has been minimized.

Copy link
Member Author

commented Feb 20, 2010

They say SHOULD not must :). In any case, I will make sure in the future that the SHOULD, with all its uppercase glory, is maintained :).

dadoonet added a commit that referenced this issue Jun 5, 2015
dadoonet added a commit that referenced this issue Jun 5, 2015
dadoonet added a commit that referenced this issue Jun 5, 2015
dadoonet added a commit that referenced this issue Jun 9, 2015
rmuir pushed a commit to rmuir/elasticsearch that referenced this issue Nov 8, 2015
Merge pull request elastic#6 from dadoonet/master
Update maven assembly plugin version to 2.3
rahul1193 referenced this issue in rahul1193/elasticsearch Jan 11, 2017
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.