Problem creating query

I need to create a query that throws the following:

{
"occurrences": [
{
"providerName": "",
"resourceCount": 123,
"registryCount": 123
}
]
}

It would be a kind of groupby by ProviderName

I have done the following

client.search({
index: 'sibdataportal',
type: 'occurrence',
body: {
"query":{
"term" : {
"provider.id" : 4
}
},

"_source": ["provider.id"],
"aggs":{
"group_by_provider": {
  "terms": {
    "field": "provider.id"
  }
}
}

}

}
Structure

"_index" : "sibdataportal",
"_type" : "occurrence",
"_id" : "5968dd8a951e3877ac39f5a2",
"_score" : 1.0,
"_source" : {
"basis_of_record" : {
"name" : "HumanObservation"
},
"canonical" : "Carollia perspicillata",
"catalog" : {
"number" : "2009.0122"
},
"collection" : {
"code" : "Asociacion de Becarios de Casanare"
},
"continent_interpreted" : "América",
"country_capital_interpreted" : "Bogotá",
"country_iso_code_interpreted" : "CO",
"country_name" : "Colombia",
"country_name_english_interpreted" : "Colombia",
"country_name_spanish_interpreted" : "Colombia",
"country_name_verbatim" : "Colombia",
"day_start" : 24,
"department_interpreted" : "Casanare",
"department_name" : "Casanare",
"department_name_verbatim" : "Casanare",
"dwca_id" : "ABC-MURCIELAGOS-2009-0122",
"eventdate_start" : "2009-01-24T00:00:00-05:00",
"habitat" : "Bosque de tierra firme",
"id" : 6492152,
"institution" : {
"code" : "ABC"
},
"locality" : "Laguna el Tinije",
"location" : {
"lat" : 4.89430555555556,
"lon" : -72.4023888888889
},
"month_start" : 1,
"occurrenceid" : "ABC-MURCIELAGOS-2009-0122",
"provider" : {
"address" : "Calle 17 No. 15 - 55",
"city" : "Yopal",
"description" : "La Asociación de Becarios de Casanare esta conformada por becarios del fondo educativo de la BP para Casanare. El nodo cuenta con información de aves, peces, anfibios, reptiles, plantas, insectos y murcielafgos en el marco del proyecto “Establecimiento de la Composición Biológica y Estructura Ecológica de la Laguna El Tinije, Casanare, Colombia",
"email" : "contacto@abccolombia.org",
"id" : 3,
"name" : "Asociación de Becarios del Casanare - ABC",
"phone" : "57 (8) 6358938",
"website_url" : "http://asociacionbecarioscasanare.org/"
},
"resource" : {
"alternate_identifier" : "doi:10.15472/ch49b6",
"citation" : "Asociación Becarios de Casanare - ABC (2009). Mamíferos voladores laguna El Tinije, 593 registros, aportados por Ramírez, B.( Publicador, Creador del Recurso, Proveedor de los Metadatos), Rodríguez, M. (Autor), En línea, http://ipt.sibcolombia.net/sib/manage/resource.do?r=abc-2009-murcielagos, publicado el 04/12/2012.",
"description" : "La tabla contiene 593 registros de murciélagos en la Laguna El Tinije. Mediante el estudio de la comunidad de murciélagos, se evaluó el estado de conservación de la localidad. La captura de murciélagos se realizó utilizando redes de niebla de 50/2 denier, 38 mm (Avinet) ubicadas en el sotobosque.Las redes se mantuvieron abiertas entre las 18:00h y 06:00h aproximadamente.",
"gbif_package_id" : "acdf883a-82fc-4181-bbdc-6f47d46e8b6c",
"hierarchy_level" : "dataset",
"id" : 38,
"intellectual_rights" : "To the extent possible under law, the publisher has waived all rights to these data and has dedicated them to the <a href="http://creativecommons.org/publicdomain/zero/1.0/legalcode">Public Domain (CC0 1.0). Users may copy, modify, distribute and use the work, including for commercial purposes, without restriction.",
"keyword" : "Murciélagos, mamíferos, laguna El Tinije.",
"keyword_thesaurus" : "n/a",
"language" : "spa",
"logo_url" : "https://s3.amazonaws.com/IPT/img/logos/abc.png",
"name" : "Mamíferos voladores laguna El Tinije",
"publication_date" : "2017-02-17T00:00:00-05:00",
"title" : "Mamíferos voladores laguna El Tinije"
},
"sourcefileid" : "abc-2009-murcielagos",
"taxon_rank" : "Especie",
"taxonomy" : {
"class_name" : "Mammalia",
"family_name" : "Phyllostomidae",
"genus_name" : "Carollia",
"kingdom_name" : "Animalia",
"order_name" : "Chiroptera",
"phylum_name" : "Chordata",
"species_name" : "Carollia perspicillata",
"specific_epithet" : "perspicillata"
},
"year_start" : 2009
}
}

Hi,

I'm a little confused if you are looking to do something beyond the regular
terms aggregation, or whether the terms aggregation is not working as you expect.

How do registryCount and resourceCount relate to the fields of your documents?

I am interested in extracting the resourcesCount with an aggregations but as I have it does not work, porq does not do the groupby by ProviderName

mind sharing your full query? I do not see a reason why
you cannot bucket by the id field

I need to group by Provider.Name to be able to count how many Resource Documents exist per provider.

Which generates an error generally which is fixed with Fielddata = true, but regenerates the mapping and inserts the data again and returns the error

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