Hi. I have the following type of documents:
{ doc_title : "doc1",
classifications: [
{assigned_classification : [
{schema: "sch1"},
{symbol: "ASD34"} ]
},
{assigned_classification : [
{schema: "sch1"},
{symbol: "DWW65"} ]
},
{assigned_classification : [
{schema: "sch2"},
{symbol: "5667G"} ]
} ]
}
{ doc_title : "doc2",
classifications: [
{assigned_classification : [
{schema: "sch1"},
{symbol: "DFG65"} ]
},
{assigned_classification : [
{schema: "sch2"},
{symbol: "34XXX"} ]
} ]
}
I would like to build a facet on "symbol" ONLY for those with schema="sch1" (i.e. faceting on symbols from the schema sch1)
I tried the following:
OPTION 1 (failed)
- create a nested mapping on the field "classifications":
{
"type1" : {
"properties" : {
"classifications" : {
"type" : "nested"
}
}
}
}
- use the following query with facet:
{
"query": {
"query_string": {
"query": "doc_title:doc*"
}
},
"from": 0,
"size": 10,
"sort": [],
"facets": {
"facet_concepts": {
"terms": {
"field": "classifications.assigned_classification.symbol",
"params": {
"target": "classifications.assigned_classification.schema",
"value": "sch1"
},
"script": "doc[target].value == value",
"_cache": false,
"size": 10,
"order": "count"
}
}
}
}
This didnt work because it gives as results in the facets ALSO symbols from the schema "sch2".
OPTION 2 (failed)
- create a nested mapping on the field "classifications":
{
"type1" : {
"properties" : {
"classifications" : {
"type" : "nested"
}
}
}
}
- use the following query with facet:
{
"query": {
"query_string": {
"query": "doc_title:doc*"
}
},
"from": 0,
"size": 10,
"sort": [],
"facets": {
"facet_concepts": {
"terms": {
"field": "classifications.assigned_classification.symbol",
"_cache": false,
"size": 10,
"order": "count"
},
"facet_filter": {
"term": {
"classifications.assigned_classification.schema": "sch1"
}
}
}
}
}
This also didnt work because it gives as results in the facets ALSO symbols from the schema "sch2".
COULD you indicate why it is failing?
I guess it is because the definition of the nested object and the structure of the documents, but I am not sure.
Many thanks !!!