Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8464631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:48:25+00:00 2026-06-10T14:48:25+00:00

I want to run an elastic search query which groups data by the combination

  • 0

I want to run an elastic search query which groups data by the combination of two different fields (Latitude and Longitude)

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 
            } 
        } 
    } 
}'

It gives a double number of results than expected… any idea?

The more relevants parts of the answer are…

_shards":{
    "total":5,
    "successful":5,
    "failed":0
},
"hits":{
    "total":**37**,
    "max_score":3.9314494,
    "hits":[{

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)

"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},.....

So, the facet grouping is done separetely (by latitude and then by longitude).

Please notice that I cannot group only by latitude or longitude, as multiple records can share latitude (but have different longitude) or viceversa.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:48:26+00:00Added an answer on June 10, 2026 at 2:48 pm

    You are making a TermsFacet on multiple fields: latitude and longitude. That means that latitude and longitude are aggregated together as they were an unique field. You see an entry for each single value, which can be either a latitude or a longitude. The fact that you get 74 entries back proves that you have 74 distinct latitude and longitude values in your index, which makes sense. What do you want to achieve exactly? One facet entry for each latitude longitude pair? In that case you have two options:

    • Add an additional field to the index which contains the pair itself and then facet on it
    • Create the latitue longitude pair on the fly using a term script. Have a look at the documentation to know more. Here is an example that should help, give it a try:
    {
        "query" : {
            "match_all" : { }
        },
        "facets" : {
            "tags" : { 
                "terms" : {
                    "field" : "latitude",
                    "script" : "term + \"_\" + _source.longitude"
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to run code which needs boost libraries. I built it using CMake.
I want to run an update query. The query will be run against multiple
I want to run a CSharp process from my java server under a different
I'd like to run an Elastic Mapreduce on data from the S3 bucket com.test.mybucket
I want to get Elastic Search running in my Windows 7 environment, but being
I want to run a SELECT ... LIKE query in SQLite that is case-sensitive.
I have in input control in my page that run a query,I want run
I want run all script from the directory . Like , The directory contains
I want run a script as follows: runner: ssh 'java program &' ssh 'java
Why this code don't work,when i want run this code vwd 2008 express show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.