Tricky Query nested json array

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Tricky Query nested json array

paul
My data:

        name: Abc College
        rankingList: [
            {
                value: 8
                key: Academic 
            }
            {
                value: 8
                key: career
            }
        ]

I Need all the college with Academic >  8
My query 

 "query": {
    "bool": {
      "must": [
        {
          "match": {
            "rankingList.key": "Academic"
          }
        },
        {
          "match": {
            "rankingList.value": 9
          }
        }
    ]
 }
}

But this query give all the data has Academic and 9 in rankingList but not that has Academic whose value is 8.

response

 rankingList: [
            {
                value: 5
                key: Academic 
            }
            {
                value: 8
                key: career
            }
        ],
 rankingList: [
            {
                value: 8
                key: sports
            }
            {
                value: 5
                key: career
            }
        ]

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/781c3fbf-3518-4443-90e4-c0cf8077c02d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Tricky Query nested json array

paul


On Wednesday, 27 November 2013 14:37:29 UTC+5:30, paul wrote:
My data:

        name: Abc College
        rankingList: [
            {
                value: 8
                key: Academic 
            }
            {
                value: 8
                key: career
            }
        ]

I Need all the college with Academic >  8
My query 

 "query": {
    "bool": {
      "must": [
        {
          "match": {
            "rankingList.key": "Academic"
          }
        },
        {
          "match": {
            "rankingList.value": 9
          }
        }
    ]
 }
}

But this query give all the data has Academic and 9 in rankingList but not that has Academic whose value is 8.

response

 rankingList: [
            {
                value: 5
                key: Academic 
            }
            {
                value: 8
                key: career
            }
        ],
 rankingList: [
            {
                value: 8
                key: sports
            }
            {
                value: 5
                key: career
            }
        ]

Got the answer at

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-nested-type.html 

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6cf0760f-baf4-478a-81e3-37510fe15ce0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.