Closed marcelsalathe closed 7 years ago
_id
and other keys starting with an underscore are a part of ElasticSearch, and not a part of OpenFood products. If I use the following query, without the underscore...
{
"from": 0,
"size": "10",
"query": {
"term": {
"name_translations.de": "milch"
}
},
"sort": "id"
}
...then I would get back a result that is sorted by product id. Example in javascript:
var queryResponse = /*the response body of the above query*/;
var hits = queryResponse.hits.hits;
console.log("Found " + hits.length + " products:")
for (var hit of hits) {
console.log(' ' + hit._source.id + ': ' + hit._source.name_translations.de)
}
/*
Found 10 products:
1216: Halbentrahmte milch
1259: Frey Milch extra – Extra feine Milchschokolade
1262: Frey – Milch-Nuss – Milchschokolade mit ganzen Haselnüssen
1305: Valflora Milch
1344: MIFLOC : Kartoffelstock Instant mit Milch
1452: Lindt Hauchdünn Milch
1491: VALFLORA : Homogenisiert Halbentrahmte Milch
1492: Valflora Drink Teilentrahmte Milch
1493: VALFLORA : Milch Lait Latte Homogenisiert
1498: Migros Bio Reisdrink ohne Milch
*/
We can filter out the "_id" (Elasticsearch id) from the results, and return only "id" (Rails id). The "_id" doesn't really add value and is clearly confusing. Will incorporate into V3 of the API.
We received this bug report via email.
This query:
{"_source":true, "from":0, "size":"10", "query":{"term":{"name_translations.de":"milch"}}, "sort":["_id"]}
in products/_search/
seems to return the correct product data, but the ordering is not always the same (in fact there seem to be two types of sorted items that are being returned.