Elastic query count mismatching

Hi , we have contacts index .while querying thru java we are getting Total Hits based on the No of Hits. But we want to get the counts based on contacts count inside Hits. Here we have 4 contacts .but we are getting the count as 2. How we can achieve this. also how we can get the data of outside contacts section data with contacts data ? i have taken 1st hits as example. while getting the response i should get the 3 contacts records with outside data.note: Outside data common to all 3 contacts. please help me on this

  {
      "took" : 4,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : 40,
        "max_score" : 5.232626,
        "hits" : [
          {
            "_index" : "icontacts",
            "_type" : "i_contacts",
            "_id" : "1-8DX1HGHLGB",
            "_score" : 4.8466597,
            "_source" : {
              "dName" : "testnew234",
              "dPrimaryRegion" : null,
              "dId" : "1-8DX1LGB",
              "dCreateddt" : "2020-02-25",
              "dPrimaryFullName" : "Rajashekhar Sangu",
              "dPrimarySId" : "RS47787508",
              "contacts" : [
                {
                  "lastName" : "abcd",
                  "lECountry" : "UNITED STATES",
                  "contactId" : "1-8DWZ7gfgfDO",
                  "OContactId" : "1-8DWZ7ghhgE4",
                  "ContactCreatedDate" : "2020-02-25 03:02:45.0",
                  "type" : "CLIENT",
                  "clientIndustryName" : "OFFICE & CLINICS OF DENTISTS",
                  "clientSector" : "Industrials",
                  "firstName" : "erwe",
                  "clientType" : "Legal Counsel",
                  "lEId" : "1006689635",
                  "emailAddr" : "sitdsfjk@fd.com",
                  "lEName" : "25 ASSACENTRAL ASPARK WEST AAAAAALLC",
                  "Phone" : "+44 7896 587458"
                },
    			{
                  "lastName" : "abcd",
                  "lECountry" : "UNITED STATES",
                  "contactId" : "1-8DWdddZ7DO",
                  "OContactId" : "1-8DWZgh7E4",
                  "ContactCreatedDate" : "2020-02-25 03:02:45.0",
                  "type" : "CLIENT",
                  "clientIndustryName" : "OFFITTTCE & CLJHKINICS OF DENLKTISTS",
                  "clientSector" : "Industrials",
                  "firstName" : "erwe",
                  "clientType" : "Legal - Arranger",
                  "lEId" : "1006689635",
                  "emailAddr" : "sitdsfjk@fd.com",
                  "lEName" : "25 CEDSSNTRAL PAGJRK WEST LLC",
                  "Phone" : "+44 7896 587458"
                },
    			{
                  "lastName" : "abcd",
                  "lECountry" : "UNITED STATES",
                  "contactId" : "1-8DWZsdf7DO",
                  "OContactId" : "1-8DWZwqu7E4",
                  "ContactCreatedDate" : "2020-02-25 03:02:45.0",
                  "type" : "CLIENT",
                  "clientIndustryName" : "OFFICES & CLINSICS OF DENTSISTS",
                  "clientSector" : "Industrials",
                  "firstName" : "erwe",
                  "clientType" : "Legal Counsel",
                  "lEId" : "1006689635",
                  "emailAddr" : "sitdsfjk@fd.com",
                  "lEName" : "25 CENTRDDFAL PARK WEUUST LLC",
                  "Phone" : "+44 7896 587458"
                }
              ]
            }
          },
    	 { "_index" : "icontacts",
            "_type" : "i_contacts",
            "_id" : "1-8DX1HGHLGB",
            "_score" : 4.8466597,
            "_source" : {
              "dName" : "testnew2345",
              "dPrimaryRegion" : null,
              "dId" : "1-8DX1LDGB",
              "dCreateddt" : "2020-02-25",
              "dPrimaryFullName" : "Rajashekgfgfhar Sangu",
              "dPrimarySId" : "RS4778ss7508",
              "contacts" : [
                {
                  "lastName" : "abasdcd",
                  "lECountry" : "UNITED STATES",
                  "contactId" : "1-8DWZ7gfgfDO",
                  "OContactId" : "1-8DWZ7ghasdhgE4",
                  "ContactCreatedDate" : "2020-02-25 03:02:45.0",
                  "type" : "CLIENT",
                  "clientIndustryName" : "OFFIasdCE & CLINICS OF DENTISTS",
                  "clientSector" : "Industrials",
                  "firstName" : "erwe",
                  "clientType" : "Legal Counsel",
                  "lEId" : "1006689635",
                  "emailAddr" : "sitdsfjk@fd.com",
                  "lEName" : "25 ASSACENTRAL ASPARK WEST AAAAAALLC",
                  "Phone" : "+44 7896 587458"
                }
    			
              ]
            }
          }
    	  ]
    	  }
    	  }

pls check and update on this issue.

If you are searching for individual contacts, why not indexing individual contacts instead?

I'm not sure I have the full understanding though. Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

we have to get the contact information , based on our orders here dID is our orders id

As I said it would help if you recreate a fully working example (can be simplified a lot as it does not require to have all the fields, a typical query you want to run and the current output.

Then share what would be the expected output.

If I understand it correctly you want to know how many contracts are there attached to a customer?

Have a look here at stackoverflow. I think this topic relates to your use case.

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