Limiting Query to 1 Item within a source


(Velusamy Velu) #1

Friends:

I have the following document a structural hierarchy, indexed.

{  
   "id":"abc",
   "nodeCount":12,
   "edgeCount":11,
   "degreesCountMap":[  
      {  
         "size":2,
         "count":10
      },
      {  
         "size":3,
         "count":2
      }
   ]
}

Then I ran the query:

{  
   "query":{  
      "bool":{  
         "must":[  
            {  
               "range":{  
                  "degreesCountMap.size":{  
                     "from":3
                  },
                  "degreesCountMap.count":{  
                     "from":10
                  }
               }
            }
         ]
      }
   }
}

Expected a no match because I thought ES will try to match {"size":3,"count":2} or {"size":2,"count":10} however, the document was matched. I assume it matched size:3 from {"size":3,"count":2} and count:10 from another {"size":2,"count":10}. My question: Is there a way to force the match to happen with one {...}.

I have also tried the query below and found the same result:

{  
   "query":{  
      "bool":{  
         "must":[  
            {  
               "range":{  
                  "degreesCountMap.size":{  
                     "from":3
                  }
               }
            },
            {  
               "range":{  
                  "degreesCountMap.count":{  
                     "from":10
                  }
               }
            }
         ]
      }
   }
}

I will appreciate your help.


(Velusamy Velu) #2

Found the answer in this post Managing Relations Inside Elasticsearch


(Ivan Brusic) #3

Elasticsearch/Lucene will bunch each inner field into the same bucket
causing the behavior you noticed. You would need to define each inner
object as a nested object [1] and use a nested query [2] to limit the query
on a single nested document.

See
https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-objects.html

[1]
https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html
[2]
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html


(Velusamy Velu) #4

Ivan:

Thanks for your reply. As I mentioned I did find the information I was looking for at Managing Relations Inside Elasticsearch.


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.