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 8393055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:41:14+00:00 2026-06-09T19:41:14+00:00

I have some customer documents that I want to be retrieved using ElasticSearch based

  • 0

I have some customer documents that I want to be retrieved using ElasticSearch based on where the customers come from (country field is IN an array of countries).

[
  {
    "name": "A1",
    "address": {
      "street": "1 Downing Street"
      "country": {
        "code": "GB",
        "name": "United Kingdom"
      }
    }
  },
  {
    "name": "A2",
    "address": {
      "street": "25 Gormut Street"
      "country": {
        "code": "FR",
        "name": "France"
      }
    }
  },
  {
    "name": "A3",
    "address": {
      "street": "Bonjour Street"
      "country": {
        "code": "FR",
        "name": "France"
      }
    }
  }
]

Now, I have another an array in my Python code:

["DE", "FR", "IT"]

I’d like to obtain the two documents, A2 and A3.

How would I write this in PyES/Query DSL? Am I supposed to be using an ExistsFilter or a TermQuery for this. ExistsFilter seems to only check whether the field exists or not, but doesn’t care about the value.

  • 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-09T19:41:16+00:00Added an answer on June 9, 2026 at 7:41 pm

    In NoSQL-type document stores, all you get back is the document, not parts of the document.

    Your requirement: “I’d like to obtain the two documents, A2 and A3.” implies that you need to index each of those documents separately, not as an array inside another “parent” document.

    If you need to match values of the parent document alongside country then you need to denormalize your data and store those values from the parent doc inside each sub-doc as well.

    Once you’ve done the above, then the query is easy. I’m assuming that the country field is mapped as:

    country: {
    type: “string”,
    index: “not_analyzed”
    }

    To find docs with DE, you can do:

    curl -XGET 'http://127.0.0.1:9200/_all/_search?pretty=1'  -d '
    {
       "query" : {
          "constant_score" : {
             "filter" : {
                "term" : {
                   "country" : "DE"
                }
             }
          }
       }
    }
    '
    

    To find docs with either DE or FR:

    curl -XGET 'http://127.0.0.1:9200/_all/_search?pretty=1'  -d '
    {
       "query" : {
          "constant_score" : {
             "filter" : {
                "terms" : {
                   "country" : [
                      "DE",
                      "FR"
                   ]
                }
             }
          }
       }
    }
    '
    

    To combine the above with some other query terms:

    curl -XGET 'http://127.0.0.1:9200/_all/_search?pretty=1'  -d '
    {
       "query" : {
          "filtered" : {
             "filter" : {
                "terms" : {
                   "country" : [
                      "DE",
                      "FR"
                   ]
                }
             },
             "query" : {
                "text" : {
                   "address.street" : "bonjour"
                }
             }
          }
       }
    }
    '
    

    Also see this answer for an explanation of how arrays of objects can be tricky, because of the way they are flattened:

    Is it possible to sort nested documents in ElasticSearch?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of Customers. Each customer has an address and some customers
I have some arbitrary pixel data that I want to save as a PNG.
I have a problem at some customer pc's (new Dell PCs) windows XP Professional
I have a datatable with data in it (customer addresses). In some instances, column
Our organization's software is compiled for the .NET 3.5 Framework. We have some customers
some of our customers have Quick book online and some of our customers have
I have a form with a DataGridView showing a list of customers, and some
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have a web application (.war) that contains some static files (e.g. MS word
I have an XML schema and an instance document I get from a customer.

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.