I have a property which can have multiple values, but it typically only has one value. It is defined as:
<property name="sc:productName">
<title>Products</title>
<type>d:text</type>
<mandatory>false</mandatory>
<multiple>true</multiple>
<index enabled="true">
<atomic>true</atomic>
<stored>false</stored>
<tokenised>both</tokenised>
</index>
</property>
I need to find all the documents that have more than one assigned product. Or:
num(sc:productName) > 1
How can I do this in a query?
Solved! Go to Solution.
Hi
The only way you can do that today is with the public API in 5.2.1. This should count the number of titles for each doc.
{
"query": {
"query": "name:*"
},
"facetFields": {
"facets": [
{"field": "DBID", "label": "DBID"}
]
},
"stats": [{
"field" : "title",
"label" : "Title"
}],
"pivots" : [
{
"key": "DBID",
"pivots": [
{
"key": "Title"
}
]
}
]
}
It does not have a way to get rid of counts you do not want.
In earlier versions you could go direct to SOLR and use the JSON facet API where you can expose what would normally be the "having" clause on the aggregate.
It will be a a bit of a pain as you will have to pick the correct field from the real solr schema.
Andy
There is no query variant via default Alfresco Java APIs or any of the search languages for this particular use case.
Axel Faust is usually correct about these things. I will ask around to see if we have a recommendation for this query.
It would help me to better understand the context around this requirement. What causes you to need to do this?
I suspect you are right. I'd be happy to use Solr directly if it supported the query.
I guess the best solution is to find all the documents with the property set at all... And then iterate through the results to find the documents I need.
Yeah. I'm trying to align the metadata in two different repositories. This property is split in the other repo. (Singleton value property and then multivariate property if more than one value is needed.) I wanted to see how much work this was going to be.
Hi
The only way you can do that today is with the public API in 5.2.1. This should count the number of titles for each doc.
{
"query": {
"query": "name:*"
},
"facetFields": {
"facets": [
{"field": "DBID", "label": "DBID"}
]
},
"stats": [{
"field" : "title",
"label" : "Title"
}],
"pivots" : [
{
"key": "DBID",
"pivots": [
{
"key": "Title"
}
]
}
]
}
It does not have a way to get rid of counts you do not want.
In earlier versions you could go direct to SOLR and use the JSON facet API where you can expose what would normally be the "having" clause on the aggregate.
It will be a a bit of a pain as you will have to pick the correct field from the real solr schema.
Andy
Well, if you can do that with the public API you should be able to do it with the Java API as well, right?
Hi
Yes, you can do it in the Java API as that is how we implement the public API - but again only on 5.2.1.
In general the public API is cleaner. The Java API has a couple of oddities for things like multi-select facets - but these do not matter for this case.
They were a pain to do in a backwards compatible way with the Java API.
Andy
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.