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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:35:10+00:00 2026-06-09T09:35:10+00:00

I have some data like so in elasticsearch: account (http://localhost:9200/myapp/account/1) ======== name state groups

  • 0

I have some data like so in elasticsearch:

account (http://localhost:9200/myapp/account/1)
========
name
state
groups //groups is an array containing objects like so {id: 1, starred: true}
       //the id is the id of the group type

email (http://localhost:9200/myapp/email/1?parent=1)
========
email
primary //just a boolean to denote whether this email is primary or not

group
========
name
description

emails are children of account.

Based on imotov’s excellent answer, I am able to run a search on account.name and email.email and return ALL accounts where the searched prefix matches the above 2 fields:

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "statuses": "active"
          }
        }
      ],
      "should": [
        {
          "prefix": {
            "name": "a"
          }
        },
        {
          "has_child": {
            "type": "email",
            "query": {
              "prefix": {
                "email": "a"
              }
            }
          }
        }
      ],
      "minimum_number_should_match" : 1
    }
  }
}

What I would like to do now is to return 2 custom fields for each result:

  • For each result return a field called email, if the search was matched on the email type (which is a child of account), return that email, otherwise return the primary email linked to the account, if none, null can be returned.

  • For each result return a field called group. The value of the field should contain the name of the starred group whose id is stored in the groups array. Essentially: Find group.id where group.starred is true in each account.groups, then return the matching group.name from the group type base on the id we found.

I have been looking at script fields, but I am not sure if it is able to return fields for each hit. I am also not sure if the above is actually accomplishable in ES.

Could someone provide some pointers as to whether this is possible and how to get started?

  • 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-09T09:35:11+00:00Added an answer on June 9, 2026 at 9:35 am

    Currently, there is simply no way to get to access the data in a has_child or nested clause.

    The only solution is to get some data, make some decisions on the client and then get more data.

    Here’s what I did to achieve it:

    • Run the query above and get back the data.

    • To deal with showing the match emails or the primary email (run on the email type):

      {"query":
          {"bool":{
             "should":{
              {
                 "prefix":{
                    "email" : "the query"
                 }
              },
              {
                 "terms":{
                    "_parent" : ["list", "of", "account", "ids"]
                }
             }
            }
          }
        }
      }
      

    Base on the above query, we can get any email addresses that were matched by the search term. Remember to set the fields in the above query to include _parent.

    We can then use array_diff() or a similiar function in languages other than PHP to diff the parent ids from above and and original query. This should then give us a list of accounts where no email was matched. Simply then send another request to get the primary emails for those accounts.

    For the groups, send a query to type account and:

    • Constrain _id to the list of account ids.
    • Constrain group.starred to true.

    This should get you a list of starred groups. To get more information (name etc), send a query to type group and:

    • Constrain _id to the group ids above.

    Finally, do some client side processing to put it together so that it is easier for the next part of your program to use.

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

Sidebar

Related Questions

Hi I have some data thats represented like this: 0,tcp,http,SF,239,486,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,8,8,0.00,0.00,0.00,0.00,1.00,0.00,0.00,19,19,1.00,0.00,0.05,0.00,0.00,0.00,0.00,0.00,normal. Its from the kdd
I have some data in MongoDB that looks like this: { name: Steve, location:
I have some data on my table like: DAY | QTY | Name 1/1/2010
I have some data like this : 1 TC1 PASS 2 TC2 FAIL 3
I have some data like this: -1,2752 -1,4735 1 -0,5500 1,3287 2 -1,6293 -2,1460
I have some data formated like the following 2009.07.02 02:20:14 40.3727 28.2330 6.4 2.6
I have some data which look like that: PMID- 19587274 OWN - NLM DP
I have some data that I would like to visualize. Each byte of the
I have some data that looks something like this... +----------+----------+----------+ | Column 1 |
I have some data from log files and would like to group entries by

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.