SOLR json request API syntax on facet domain with filter & field list
Hello everybody, I work on a SOLR version 6.0.0. I use the JSON request API to facet the results. Here is a SOLR query example : {"query":"object_type_s:contact","params":{"wt":"json","start":0,"rows":10},"filter":[],"facet":"byNestedGammes":{"type":"terms","field":"gamme","domain":{"blockChildren":"object_type_s:contact"},"sort":"index","limit":-1},"byEtatMarketing":{"type":"terms","field":"etat_marketing_s","sort":"count","limit":-1},"bySuite":{"type":"terms","field":"kits_sans_suite_ss","sort":"count","limit":-1},"byAgeInactivite":{"type":"terms","field":"age_inactivite_s","domain":{"excludeTags":"byAgeInactivite"},"sort":"count","limit":-1},"byTTC":{"type":"terms","field":"TTC_i","domain":{"blockChildren":"object_type_s:contact","filter":"enseigne_s:INI"},"sort":"index","limit":-1}},"sort":""} For the "byTTC" facet, the "domain" parameter with "blockChildren" returns all values of TTC_i, a field nested in a parent document. Example : "id":"693897.870735", "asso_i":693897, "personne_i":870735, "etat_technique_s":"avec_documents", "etat_marketing_s":"actif", "type_parent_s":"Société", "groupe_type_parent_s":"SOCIETE", "_childDocuments_":[ { "kit_sans_suite":["false"], "TTC_i":300, "type_cde_s":"DEVIS", "object_type":["order"], "enseigne_s":"INI"} I don't underdtand why the results are the same for the facet byTTC with or without filter parameter in the domain ("domain":{"blockChildren":"object_type_s:contact","filter":"enseigne_s:INI"). It should filter the results when in a child document "enseigne_s" has the value "INI", but not... I thought I had to add the field list parameter to return child documents with parent documents (like on the solr UI admin : "fl":"*,[child parentFilter=object_type_s:contact]"), but I can't find the syntax for that parameter in the JSON request API... Thanks for your help. Best JB -- Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Re: Sum and aggregation on nested documents field
My apologize Mikhail, I try to explain it better : This is actually what I get from SOLR with the query you helped me to build : "responseHeader":{ "status":0, "QTime":15, "params":{ "q":"{!parent which=object_type_s:contact score=max v=$chq}", "indent":"on", "fl":"*,score,[child parentFilter=object_type_s:contact]", "fq":["_query_:\"{!parent which=object_type_s:contact} (enseigne_s:SAV AND (type_cde_s:CDE OR type_cde_s:REASSORT) AND campagne_s:G)\"", "-_query_:\"{!parent which=object_type_s:contact} (enseigne_s:SAV AND type_cde_s:KIT AND campagne_s:I)\"", "{!frange l=3}{!parent which=object_type_s:contact score=total v=$chq}"], "chq":"+object_type:order +campagne_s:G +enseigne_s:SAV +type_cde_s:(CDE OR REASSORT) {!func}TTC_i", "wt":"json", "debugQuery":"on", "_":"1531145722719"}}, "response":{"numFound":2,"start":0,"maxScore":31640.16,"docs":[ { "id":"94000.94001.1117636", "parent_i":94000, "asso_i":94001, "personne_i":1117636, "object_type_s":"contact", "date_derni_re_commande_dt":"2017-11-13T00:00:00Z", "_version_":160558310031362, *"score":31640.16*, "_childDocuments_":[ { "object_type":["order"], "TTC_i":0, "type_cde_s":"KIT", "campagne_s":"G", "enseigne_s":"SAV" }, { "object_type":["order"], "TTC_i":31636, "type_cde_s":"CDE", "campagne_s":"G", "enseigne_s":"SAV" } I already get the TTC_i sum, by parent document with the "score" parameter. If I correctly understand, the {!frange} allows me to filter on that "score", so I can get the result of that question : "get the parent which sum of TTC_i, with campagne_s:G and enseigne_s:SAV and type_cde_s:CDE or type_cde_s:REASSORT, is higher than 3". If you think it's OK, I get the results I wanted. Then my goal is to build a facet to get the number of parent docs which answer to the query, with others constraints (like only one campagne_s, etc). I think I have to use the json facet API, with facet.pivot for example. Do you think I'm on the right way ? Best JB -- Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Re: Sum and aggregation on nested documents field
Hello Mikhail, First thanks a lot for your answers which are very useful for me... Then, I tried the query with the '$' parameter, and I get some great result like this : "id":"693897", "asso_i":693897, "etat_technique_s":"avec_documents", "etat_marketing_s":"actif", "type_parent_s":"Société", "groupe_type_parent_s":"SOCIETE", "nombre_commandes_brut_i":121, "nombre_commandes_i":101, "nombre_kits_saveur_i":0, "ca_periode_i":60524, "ca_periode_fleur_i":0, "ca_periode_saveur_i":58148, "zone_scolaire_s":"B", "territoire_s":"France Métropolitaine", "region_s":"CENTRE VAL DE LOIRE", "departement_s":"45 LOIRET", "postal_country_s":"FR", "asso_country_s":"FRANCE", "object_type_s":"contact", "date_derni_re_commande_dt":"2016-04-21T00:00:00Z", "_version_":1605523881394177, *"score":308940.0*, "_childDocuments_":[ { "fixe_facturation":["0238756400"], "object_type":["order"], "TTC_i":29120, "kit_sans_suite":["false"], "fixe_livraison":["0238756400"], "type_cde_s":"CDE", "statut_s":"V", "campagne_s":"A", "date_dt":"2016-04-19T00:00:00Z", "id":"A22058", "enseigne_s":"SAV", "gamme":["CHOCOLAT > Assortiment", "CHOCOLAT > Mono-produit", "EQUIPEMENT MAISON > Contenant pour liquide", "SAVEURS > Pâtisserie"]}, { "fixe_facturation":["0238765400"], "object_type":["order"], "TTC_i":429, "kit_sans_suite":["false"], "fixe_livraison":["0238756400"], "type_cde_s":"CDE", "statut_s":"V", "campagne_s":"A", "date_dt":"2016-04-21T00:00:00Z", "id":"A22511", "enseigne_s":"BRI", "gamme":["SAVEURS > Pâtisserie"]} The query looks like that : /solr//select?chq=%2Bobject_type:order%20{!func}TTC_i=on=*,score,[child%20parentFilter=object_type_s:contact]=on={!parent%20which=object_type_s:contact%20score=total%20v=$chq}=json I also test the queries on the SOLR admin interface, and when I get what I expect, I work on the development of the IHM which provides facet counting and filtering for users. The total score of TTC is a great advanced for me, but I need now to facet the results or to be able to filter on the score returned. I already tried using frange in filter query : {!frange l=0 u=1 inclusive=true}$chq I also tried : {!frange l=0 u=1 inclusive=true}TTC_i With inclusive = false... Without any result. I know I'm not so far, could you put me on the right way if you have an idea ? Thanks for your time, Best JB -- Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Sum and aggregation on nested documents field
Hello everybody, I have a question about how to retrieve results from SOLR with some aggregation (like sum in my case...) on the nested documents. First, the data SOLR returned with a standard query : { "id":"3911.3912.1278", "parent_i":3191, "asso_i":3112, "personne_i":16278, "etat_technique_s":"avec_documents", "etat_marketing_s":"actif", "type_parent_s":"Ecole élémentaire publique", "type_asso_s":"APE (association de parents d'élèves)", "groupe_type_parent_s":"ENSEIGNEMENT_PRIMAIRE", "groupe_type_asso_s":"ASSOCIATION_DE_PARENTS", "nombre_commandes_brut_i":8, "nombre_commandes_i":3, "nombre_kits_saveur_i":4, "ca_periode_i":2977, "ca_periode_fleur_i":0, "ca_periode_saveur_i":2977, "zone_scolaire_s":"C", "territoire_s":"France Métropolitaine", "region_s":"LANGUEDOC-ROUSSILLON MIDI-PYRENEES", "departement_s":"30 GARD", "postal_country_s":"FR", "asso_country_s":"FRANCE", "object_type_s":"contact", "kits_sans_suite_ss":["Initiatives Saveurs"], "date_derni_re_commande_dt":"2017-11-14T00:00:00Z", "_version_":1605492468379287553, "_childDocuments_":[ { "fixe_facturation":["0465221792"], "object_type":["order"], "TTC_i":1200, "mobile_livraison":["0672655536"], "kit_sans_suite":["true"], "fixe_livraison":["0466421792"], "type_cde_s":"KIT", "statut_s":"V", "mobile_facturation":["0675255536"], "campagne_s":"A", "date_dt":"2016-01-24T00:00:00Z", "id":"A04520", "enseigne_s":"SAV", "gamme":["KITS > Kits Saveurs"]}, { "fixe_facturation":["0466521792"], "object_type":["order"], "TTC_i":15, "mobile_livraison":["0672655536"], "kit_sans_suite":["false"], "fixe_livraison":["0464221792"], "type_cde_s":"DOCUMENTATION", "statut_s":"V", "mobile_facturation":["0672655536"], "campagne_s":"B", "date_dt":"2016-09-29T00:00:00Z", "id":"B15755", "enseigne_s":"INI", "gamme":["CATALOGUES > Catalogues Brioche", "CATALOGUES > Catalogues Fleurs et Nature"]}, { "fixe_facturation":["0465221792"], "object_type":["order"], "TTC_i":156, "mobile_livraison":["0672655536"], "kit_sans_suite":["false"], "fixe_livraison":["0466221492"], "type_cde_s":"KIT", "statut_s":"V", "mobile_facturation":["0672245536"], "campagne_s":"B", "date_dt":"2016-09-29T00:00:00Z", "id":"B15769", "enseigne_s":"SAV", "gamme":["KITS > Kits Saveurs"]} My goal is to get with one SOLR query the sum of TTC_i by parent document... I tried with facet.pivot, stats, group, with no results... Thanks for your advices Best JB -- Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Re: Sum and aggregation on nested documents field
Thanks for your reply Mikhail, I tried like this : "{!parent which=object_type_s:contact score=total v={!func}TTC_i}" in a filter query, the same in the sort parameter, I also tried to put this query "{!parent which=object_type_s:contact score=total}TTC_i" into the q parameter, but no results... I had a look to the dismax query parser, but I'm not sure it is a way to solve my problem. So what's wrong with my function query ? Did I explicite the child level correctly ? Best JB -- Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Re: Sum and aggregation on nested documents field
Thanks for your reply Mikhail, I tried like this : "{!parent which=object_type_s:contact score=total v={!func}TTC_i}" in a filter query, the same in the sort parameter, I also tried to put this query "{!parent which=object_type_s:contact score=total}TTC_i" into the q parameter, but no results... I had a look to the dismax query parser, but I'm not sure it is a way to solve my problem. So what's wrong with my function query ? Did I explicite the child level correctly ? Best JB -- Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Sum and aggregation on nested documents field
Hello everybody, First, an example of a parent document with 2 nested documents : { "id":"10891.10893.142693", "parent_i":10891, "asso_i":10893, "personne_i":142693, "etat_technique_s":"avec_documents", "zone_scolaire_s":"B", "territoire_s":"France Métropolitaine", "region_s":"PROVENCE-ALPES-COTE D'AZUR", "departement_s":"13 BOUCHES-DU-RHONE", "postal_country_s":"FR", "asso_country_s":"FRANCE", "object_type_s":"contact", "date_derni_re_commande_dt":"2017-11-21T00:00:00Z", "_version_":1605492468358316033, "_childDocuments_":[ { "kit_sans_suite":["false"], "TTC_i":152, "type_cde_s":"KIT", "object_type":["order"], "statut_s":"V", "campagne_s":"G", "date_dt":"2017-09-28T00:00:00Z", "id":"G15608", "enseigne_s":"SAV", "gamme":["CATALOGUES > Catalogues Saveurs", "KITS > Kits Saveurs"]}, { "object_type":["order"], "TTC_i":2793, "kit_sans_suite":["false"], "type_cde_s":"CDE", "statut_s":"V", "campagne_s":"G", "date_dt":"2017-11-21T00:00:00Z", "id":"G43625", "enseigne_s":"SAV", } } And i would like to get a sum of TTC_i field, by parent document... I tried with stats, pivot, without any results... Thanks for your help. Best JB -- Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Re: _childDocuments_ automatically multivalued field type
Ok, I'll have a look at the link above. Thanks a lot... Best JB -- Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Re: _childDocuments_ automatically multivalued field type
Ok, I see what I have to look for, thanks to your reply. I'll adjust the schema and see difference. Thanks. Best JB -- Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
_childDocuments_ automatically multivalued field type
Hello everybody, I have a problem with some field types in the managed-schema generated. First, the data SOLR returned with a standard query : response":{"numFound":365567,"start":0,"docs":[ { "id":"560.561.134676", "parent_i":560, "asso_i":561, "personne_i":134676, "etat_technique_s":"avec_documents", "etat_marketing_s":"actif", "type_parent_s":"Ecole élémentaire publique", "type_asso_s":"APE (association de parents d'élèves)", "groupe_type_parent_s":"ENSEIGNEMENT_PRIMAIRE", "groupe_type_asso_s":"ASSOCIATION_DE_PARENTS", "nombre_commandes_brut_i":2, "nombre_commandes_i":1, "nombre_kits_saveur_i":0, "ca_periode_i":560, "ca_periode_fleur_i":0, "ca_periode_saveur_i":0, "zone_scolaire_s":"A", "territoire_s":"France Métropolitaine", "region_s":"AUVERGNE RHONE-ALPES", "departement_s":"01 AIN", "postal_country_s":"FR", "asso_country_s":"FRANCE", "object_type_s":"contact", "date_derni_re_commande_dt":"2016-05-20T00:00:00Z", "_version_":1604889647955050496, "_childDocuments_":[ { "fixe_facturation":["0256897856"], "object_type":["order"], "mobile_livraison":["0658987874"], "kit_sans_suite":["false"], "fixe_livraison":["0450598311"], "type_cde_s":"CDE", "statut_s":"V", "mobile_facturation":["0658787458"], "campagne_s":"A", "TTC":[780], "date_dt":"2016-05-20T00:00:00Z", "id":"A28837", "enseigne_s":"CRE"}, { "fixe_facturation":["0245784975"], "object_type":["order"], "mobile_livraison":["0645789874"], "kit_sans_suite":["false"], "type_cde_s":"KIT", "statut_s":"V", "mobile_facturation":["0612345678"], "campagne_s":"A", "TTC":[0], "date_dt":"2016-05-04T00:00:00Z", "id":"A25415", "enseigne_s":"CRE"}]} My goal is to sum fields "TTC" by parentDocument. But with the type "multiValued", I can't use aggregation functions. The core get the data from this script : /opt/solr/bin/post -c -format solr build/index.json The index.json looks like that: [ { "id": "781.782.134878", "parent_i": 781, "asso_i": 782, "personne_i": 134878, "etat_technique_s": "avec_documents", "etat_marketing_s": "inactif", "type_parent_s": "Ecole élémentaire privée", "type_asso_s": "APEL (association de parents école libre)", "groupe_type_parent_s": "ENSEIGNEMENT_PRIMAIRE", "groupe_type_asso_s": "ASSOCIATION_DE_PARENTS", "nombre_commandes_brut_i": 4, "nombre_commandes_i": 2, "nombre_kits_saveur_i": 2, "date_dernière_commande_dt": "2010-11-16", "ca_periode_i": 0, "ca_periode_fleur_i": 0, "ca_periode_saveur_i": 0, "zone_scolaire_s": "A", "territoire_s": "France Métropolitaine", "region_s": "AUVERGNE RHONE-ALPES", "departement_s": "01 AIN", "postal_country_s": "FR", "asso_country_s": "FRANCE", "object_type_s": "contact", "kits_sans_suite_ss": null, "_childDocuments_": [ { "fixe_facturation": "0450407279", "object_type": "order", "mobile_livraison": "0628332864", "kit_sans_suite": "false", "fixe_livraison": "0450407279", "type_cde_s": "KIT", "statut_s": "V", "mobile_facturation": "0628332864", "campagne_s": "L", "TTC": 0, "date_dt": "2009-10-12T00:00:00Z", "id": "L14276", "enseigne_s": "SAV", "gamme": [ "KITS > Kits Saveurs" ] }, { "fixe_facturation": "0450407279", "object_type": "order", "mobile_livraison": "0628332864", "kit_sans_suite": "false", "fixe_livraison": "0450407279", "type_cde_s": "CDE", "statut_s": "V", "mobile_facturation": "0628332864", "campagne_s": "L", "TTC": 1045, "date_dt": "2009-11-14T00:00:00Z", "id": "L25049", "enseigne_s": "SAV", "gamme": [ "CHOCOLAT > Assortiment", "CHOCOLAT > Individuel", "CHOCOLAT > Mono-produit", "EQUIPEMENT MAISON > Cuisine", "EQUIPEMENT MAISON > Décoration", "KITS > Kits Saveurs", "SAVEURS > Confiserie", "SAVEURS > Pâtisserie" ] } ] In the managed-schema, only those fields appear: I don't understand why for example "type_cmd_s" get the field type attribute "singleValued", but "TTC" or "kits_sans_suite" get "multiValued" attribute ? Why those field are in the managed-schema and enseigne_s (for example) is not ? Thanks a lot for your help... Best JB -- Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html