title: elastic search double facet
body: <p>I want to run an elastic search query which groups data by the combination of two different fields (Latitude and Longitude)</p>
  
  <pre><code>curl -XGET http://www.my_server:9200/idx_occurrence/Occurrence/_search?pretty=true -d '{  
      "query": { 
          "query_string" : { 
              "fields" : ["genus_interpreted","dataset"], 
              "query": "Pica 2", 
              "default_operator" : "AND" 
           } 
      }, 
      "facets": { 
          "test": { 
              "terms": { 
                  "fields" :["decimalLatitude","decimalLongitude"],
                  "size" : 500000000 
              } 
          } 
      } 
  }'
  </code></pre>
  
  <p>It gives a double number of results than expected... any idea?</p>
  
  <p>The more relevants parts of the answer are...</p>
  
  <pre><code>_shards":{
      "total":5,
      "successful":5,
      "failed":0
  },
  "hits":{
      "total":**37**,
      "max_score":3.9314494,
      "hits":[{
  </code></pre>
  
  <p>the total hits, 37 is the result of the query if I don't apply the facets. This total is the half of the total in facets (see below)</p>
  
  <pre><code>"facets":{
      "test":{
          "_type":"terms",
          "missing":0,
          "total":**74**,
          "other":0,
          "terms":[
             {"term":"167.21665954589844","count":5},
             {"term":"167.25","count":4},
             {"term":"167.14999389648438","count":4},
             {"term":"167.1041717529297","count":4},
             {"term":"-21.04166603088379","count":4},.....
  </code></pre>
  
  <p>So, the facet grouping is done separetely (by latitude and then by longitude).</p>
  
  <p>Please notice that I cannot group only by latitude or longitude, as multiple records can share latitude (but have different longitude) or viceversa.</p>