Getting unique results

Hi,
I have following mapping and data

curl -XPUT 'localhost:9200/testcompany/activity1/_mapping' -d '{
"activity" : {
"properties" : {
"organization" : {
"properties": {
"id": {"type": "string"},
"name": {"analyzer": "keyword", "type": "string"}
}
}
}
}
}'
curl -XPUT localhost:9200/testcompany/activity1/1 -d '{
"title": "title1 of project",
"organization": {"name": "ABC company", "id": "11a"}
}'
curl -XPUT localhost:9200/testcompany/activity1/2 -d '{
"title": "title2 of project",
"organization": {"name": "ABC company", "id": "11a"}
}'
curl -XPUT localhost:9200/testcompany/activity1/3 -d '{
"title": "title3 of project",
"organization": {"name": "XYZ company", "id": "12c"}
}'

I need to present the list of organizations (name and ids) with their
numbers like
ABC company (11a): 2
XYX company (12c): 1

If i do facet for id,
curl -X POST localhost:9200/testcompany/activity1/_search?pretty=true -d '{
"query" : {"match_all":{}},
"facets" : {"organization" : {"terms" : {"field": "organization.id"}}}
}'

I only get count by "ids" and using name, i get count by "names". What i
could do is get the count by ids and names and combine results, which is
definitely not a good way. Is there any possiblity of getting the unique
json results for organizations so that i could easily combine the facets
results with the sort of key-value unique results.

Thanks
Anjesh.

Hi,

Try using scripts in facets to run facets on multiple fields. Something
like :

{
"query": {
"match_all": {}
},
"size" : 0,
"facets": {
"organization": {
"terms": {
"script": "doc['organization.name'].value + "(" +
doc['organization.id'].value + ")""
}
}
}
}

This might not work properly, as I might be missing something on the
necessary syntax for nested type, as is your data, but it works plain and
simple in my case.

On Sunday, May 6, 2012 3:26:43 PM UTC+5:30, anjesh wrote:

Hi,
I have following mapping and data

curl -XPUT 'localhost:9200/testcompany/activity1/_mapping' -d '{
"activity" : {
"properties" : {
"organization" : {
"properties": {
"id": {"type": "string"},
"name": {"analyzer": "keyword", "type": "string"}
}
}
}
}
}'
curl -XPUT localhost:9200/testcompany/activity1/1 -d '{
"title": "title1 of project",
"organization": {"name": "ABC company", "id": "11a"}
}'
curl -XPUT localhost:9200/testcompany/activity1/2 -d '{
"title": "title2 of project",
"organization": {"name": "ABC company", "id": "11a"}
}'
curl -XPUT localhost:9200/testcompany/activity1/3 -d '{
"title": "title3 of project",
"organization": {"name": "XYZ company", "id": "12c"}
}'

I need to present the list of organizations (name and ids) with their
numbers like
ABC company (11a): 2
XYX company (12c): 1

If i do facet for id,
curl -X POST localhost:9200/testcompany/activity1/_search?pretty=true -d '{
"query" : {"match_all":{}},
"facets" : {"organization" : {"terms" : {"field": "organization.id"}}}
}'

I only get count by "ids" and using name, i get count by "names". What i
could do is get the count by ids and names and combine results, which is
definitely not a good way. Is there any possiblity of getting the unique
json results for organizations so that i could easily combine the facets
results with the sort of key-value unique results.

Thanks
Anjesh.