问题
Now I'm doing this request on CloudSearch
:
aws cloudsearchdomain --endpoint-url myUrl search --search-query France --query-options "{'fields':['country']}" --return name
I want to get only distinct names but i get names with id. Is there a way to do that ?
回答1:
For this example array :
country | city | company_name | company_id | product_name | product_id
US | NY | C1N | C1id | P1N | P1id
US | NY | C1N | C1id | P2N | P2id
US | NY | C2N | C2id | P1N | P1id
I want to get all distinct company_name and company_id in NY
I do this request : URL/search?q=NY&facet.company_id={sort:'count'}&q.options={"defaultOperator":"and","fields":["city"],"operators":["and","or"]}&return=_all_fields
I get distinct company_id but i don't find a way to get company_name at the same time without making another request
{
"status": {
"rid": "lKzEiL0qCwok24g=",
"time-ms": 93
},
"hits": {
"found": 2,
"start": 0,
"hit": [{
"id": "369998744556855594878962245"
}, {
"id": "3699987477777545245"
}]
},
"facets": {
"company_id": {
"buckets": [{
"value": "C1id",
"count": 2
}, {
"value": "C2id",
"count": 1
}]
}
}
}
EDIT : SOLUTION
I found a solution : I store raw json data in a new column :
json_company = {\"id\":\"C1id\",\"name\":\"C1N\"}
and my request : &facet.json_company ={}
My result :
"facets": {
"json_company": {
"buckets": [{
"value": "{\"id\":\"C1id\",\"name\":\"C1N\"}",
"count": 2
}, {
"value": "{\"id\":\"C2id\",\"name\":\"C2N\"}",
"count": 1
}]
}
I parse the JSON in my Lambda function !
来源:https://stackoverflow.com/questions/36327457/select-distinct-cloudsearch-aws