ArangoDB, How can I display graph? - graph

I am new to arangoDB. I create document collection 'sitetestcom' and edge collection 'linking'. In ArangoDB Web Interface, I set Graph Viewer Configuration with Vertex collection to sitetestcom and Edge collection to linking. But no graph is display, just 2 Vertices
How can I display graph?
Thanks in advance for helping.
Collection: sitetestcom, Type: Document
[ { "_id" : "sitetestcom/4156515209", "_rev" : "4156515209", "_key" : "4156515209", "url" : "http://sitetest.com/sentimancho", "titre" : "Sentimancho " }, { "_id" : "sitetestcom/4144718729", "_rev" : "4144718729", "_key" : "4144718729", "url" : "http://sitetest.com/infogerance", "titre" : "Infogérance " }, { "_id" : "sitetestcom/4153107337", "_rev" : "4153107337", "_key" : "4153107337", "url" : "http://sitetest.com/category/annuaire", "titre" : "Annuaire " }, { "_id" : "sitetestcom/4146946953", "_rev" : "4146946953", "_key" : "4146946953", "url" : "http://sitetest.com/creation-site", "titre" : "Création site" }, { "_id" : "sitetestcom/4154876809", "_rev" : "4154876809", "_key" : "4154876809", "url" : "http://sitetest.com/jardinchic", "titre" : "JardinChic " }, { "_id" : "sitetestcom/4151993225", "_rev" : "4151993225", "_key" : "4151993225", "url" : "http://sitetest.com/category/non-classe", "titre" : "Non classé " }, { "_id" : "sitetestcom/4128924553", "_rev" : "4128924553", "_key" : "4128924553", "url" : "http://sitetest.com/", "titre" : "Référencement " }, { "_id" : "sitetestcom/4135871369", "_rev" : "4135871369", "_key" : "4135871369", "url" : "http://sitetest.com/infogerance/", "titre" : "Infogérance " }, { "_id" : "sitetestcom/4140589961", "_rev" : "4140589961", "_key" : "4140589961", "url" : "http://sitetest.com/hebergement-mutualise", "titre" : "Hébergement mutualisé " }, { "_id" : "sitetestcom/4145046409", "_rev" : "4145046409", "_key" : "4145046409", "url" : "http://sitetest.com/developpeur-wordpress", "titre" : "Développeur WordPress " }, { "_id" : "sitetestcom/4131152777", "_rev" : "4131152777", "_key" : "4131152777", "url" : "http://sitetest.com/blog-devenir", "titre" : "" }, { "_id" : "sitetestcom/4139541385", "_rev" : "4139541385", "_key" : "4139541385", "url" : "http://sitetest.com/contact", "titre" : "Contact " }, { "_id" : "sitetestcom/4135543689", "_rev" : "4135543689", "_key" : "4135543689", "url" : "http://sitetest.com/creation-site/", "titre" : "Création site" }, { "_id" : "sitetestcom/4148257673", "_rev" : "4148257673", "_key" : "4148257673", "url" : "http://sitetest.com/serp-domination", "titre" : "SERP Domination " }, { "_id" : "sitetestcom/4150682505", "_rev" : "4150682505", "_key" : "4150682505", "url" : "http://sitetest.com/category/portfolio", "titre" : "portfolio " }, { "_id" : "sitetestcom/4130759561", "_rev" : "4130759561", "_key" : "4130759561", "url" : "http://sitetest.com/extension-magento-gestion-stocks", "titre" : "Extension Magento gestion des stocks " }, { "_id" : "sitetestcom/4149699465", "_rev" : "4149699465", "_key" : *"4149699465", "url" : "http://sitetest.com/devis-audit-referencement", "titre" : "Devis Audit Réferencement " }, { "_id" : "sitetestcom/4150027145", "_rev" : "4150027145", "_key" : "4150027145", "url" : "http://sitetest.com/offre-tout-compris", "titre" : "Offre tout compris " }, { "_id" : "sitetestcom/4140262281", "_rev" : "4140262281", "_key" : "4140262281", "url" : "http://sitetest.com/portfolio-large", "titre" : "Portfolio " }, { "_id" : "sitetestcom/4155401097", "_rev" : "4155401097", "_key" : "4155401097", "url" : "http://sitetest.com/communique-de-presse", "titre" : "Communiqué de presse " }, { "_id" : "sitetestcom/4150354825", "_rev" : "4150354825", "_key" : "4150354825", "url" : "http://sitetest.com/referencement", "titre" : "Référencement" }, { "_id" : "sitetestcom/4148585353", "_rev" : "4148585353", "_key" : "4148585353", "url" : "http://sitetest.com/netlinking", "titre" : "Netlinking " }, { "_id" : "sitetestcom/4154155913", "_rev" : "4154155913", "_key" : "4154155913", "url" : "http://sitetest.com/informatique", "titre" : "Informatique " }, { "_id" : "sitetestcom/4153631625", "_rev" : "4153631625", "_key" : "4153631625", "url" : "http://sitetest.com/immobilier", "titre" : "" }, { "_id" : "sitetestcom/4135216009", "_rev" : "4135216009", "_key" : "4135216009", "url" : "http://sitetest.com/referencement/", "titre" : "Référencement" }, { "_id" : "sitetestcom/4130431881", "_rev" : "4130431881", "_key" : "4130431881", "url" : "http://sitetest.com/cables", "titre" : "cables" } ]*
Collection: linking, Type: Edge
[ { "_id" : "linking/4153435017", "_rev" : "4153435017", "_key" : "4153435017", "_from" : "sitetestcom/4131152777", "_to" : "sitetestcom/4153107337", "what" : 1 }, { "_id" : "linking/4155204489", "_rev" : "4155204489", "_key" : "4155204489", "_from" : "sitetestcom/4140262281", "_to" : "sitetestcom/4154876809", "what" : 1 }, { "_id" : "linking/4154483593", "_rev" : "4154483593", "_key" : "4154483593", "_from" : "sitetestcom/4140262281", "_to" : "sitetestcom/4154155913", "what" : 1 }, { "_id" : "linking/4152320905", "_rev" : "4152320905", "_key" : "4152320905", "_from" : "sitetestcom/4130759561", "_to" : "sitetestcom/4151993225", "what" : 1 }, { "_id" : "linking/4151206793", "_rev" : "4151206793", "_key" : "4151206793", "_from" : "sitetestcom/4130431881", "_to" : "sitetestcom/4150682505", "what" : 1 }, { "_id" : "linking/4153959305", "_rev" : "4153959305", "_key" : "4153959305", "_from" : "sitetestcom/4140262281", "_to" : "sitetestcom/4153631625", "what" : 1 }, { "_id" : "linking/4155728777", "_rev" : "4155728777", "_key" : "4155728777", "_from" : "sitetestcom/4148585353", "_to" : "sitetestcom/4155401097", "what" : 1 }, { "_id" : "linking/4156842889", "_rev" : "4156842889", "_key" : "4156842889", "_from" : "sitetestcom/4151993225", "_to" : "sitetestcom/4156515209", "what" : 1 } ]

I imported your collections into ArangoDB.
Just a heads up: The document collection is not valid JSON, as there are some asterisks * in the data, which had to be removed first.
To the issue at hand.
When you click on the Graph menu, you can select the collections or graphs and below that is an "Advanced" box. If you click on it, it will open up a form. There are some initial settings, which you can change.
For now, without changing anything here, click on Start.
You might see a vertex or an empty graph. Don't worry.
The graph viewer by default displays a random vertex at start, but you can select a specific vertex by clicking on the "Filter" icon on the top right of the graph window.
Click this icon.
On the filter form that should have appeared now, click on the attribute name list-box and select _key.
In the attribute value field, copy and paste this key: 4140262281 (This is a vertex key from the document collection, that you attached to the question).
You should now have gotten a small graph consisting of that vertex and 3 other ones, connected by edges.
Now, if your data had more connections, you would be able to click on the vertices and any connected ones, would also get displayed.
The reason, that you were seeing only the two vertices in your screenshot, above, was, that there are no more edges connecting other vertices to those ones.
Try entering the vertex key (from the screenshot) in the filter: 4130431881. You should again get only those two.
Now, let's say you wanted to connect this vertex to the one I showed you previously.
Open up the collections, proceed into the linking collection and click the + button on the top right, in order to create a new edge-document.
Create the edge:
In the _from field enter: sitetestcom/4140262281
In the _to field enter: sitetestcom/4130431881
Hit create.
Now go back to the graph viewer and start the graph: Filter again by _key == 4140262281.
You should now see the 4140262281 Vertex and the newly connected 4130431881 vertex.
Now, if you click on the 4140262281 vertex, its connected vertex 4150682505 should appear.
Finally, in order to give the vertices a more user friendly naming (I took your titre attribute), click on the wheel button next to the filter, and click on 'vertices'-'label'.
Replace the _key entry with titre and hit Change.
You should now see the titles of the vertices instead of the _keys.
Hope that helped.
Please also take a look at this informative screen-cast from Michael, who wrote the graph viewer: https://www.youtube.com/watch?v=ASR7AX4bWjA

Related

Best way to get list of state-level places (google places api)

I'm currently working a project with the requirement to get a list of state-level places. I've tried the following two APIs but none of them can 100% meet the requirement:
Google Autocomplete API. In order to get rid off the detailed street-level places I passed types: ["(regions)"] which is OK from business' point of view (even though only state-level would be perfect, but city-level is still OK). However when user search for Washington, USA the API only returns 5 cities named Washington, and user have to search for WA, USA instead.
Google Places API. This API can successfully handle the Washington case above. However I couldn't find a way to restrict the API to get rid off the street-level places, unless I filter the returned places by the types attribute.
Does anyone know what is the best API to use for this scenario?
Doing a Text Search request with the search string as Washington, USA I get only 1 result which seems to be the WA state.
Request (use your own API key): https://maps.googleapis.com/maps/api/place/textsearch/json?query=Washington%2C%20USA&language=en&key=YOUR_API_KEY
Result:
{
"html_attributions" : [],
"results" : [
{
"formatted_address" : "Washington, USA",
"geometry" : {
"location" : {
"lat" : 47.7510741,
"lng" : -120.7401385
},
"viewport" : {
"northeast" : {
"lat" : 49.0024442,
"lng" : -116.91558
},
"southwest" : {
"lat" : 45.543541,
"lng" : -124.8489739
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/geocode-71.png",
"name" : "Washington",
"photos" : [
{
"height" : 2124,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/101488181553592859672\"\u003eArko Bhattacharjee\u003c/a\u003e"
],
"photo_reference" : "ATtYBwLa-P4aH5Uh3rD2CKaZmwb8HyNPWZ1WZUnw_y4iaUouh4B6BKOwAo52kkiBNSfn3MJmkW6Ju50H_e7zhxs5m5oBJva-dywtTv2cF_OgX6COeUfnre_SVmXw1qA4Fof924hSOvutwFnjsO6MJ1R71ozhBfieWrtvN9dSwVbgQbvMu-3y",
"width" : 1440
}
],
"place_id" : "ChIJ-bDD5__lhVQRuvNfbGh4QpQ",
"reference" : "ChIJ-bDD5__lhVQRuvNfbGh4QpQ",
"types" : [ "administrative_area_level_1", "political" ]
}
],
"status" : "OK"
}
Double check this by doing a Place Details request with the returned place id ChIJ-bDD5__lhVQRuvNfbGh4QpQ:
Request (use your own API key): https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJ-bDD5__lhVQRuvNfbGh4QpQ&language=en&key=YOUR_API_KEY
Result:
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "Washington",
"short_name" : "WA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"adr_address" : "\u003cspan class=\"region\"\u003eWashington\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUSA\u003c/span\u003e",
"formatted_address" : "Washington, USA",
"geometry" : {
"location" : {
"lat" : 47.7510741,
"lng" : -120.7401386
},
"viewport" : {
"northeast" : {
"lat" : 49.00256875707851,
"lng" : -116.9155800245149
},
"southwest" : {
"lat" : 45.54354101516995,
"lng" : -124.8489739457119
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/geocode-71.png",
"name" : "Washington",
"photos" : [],
"place_id" : "ChIJ-bDD5__lhVQRuvNfbGh4QpQ",
"reference" : "ChIJ-bDD5__lhVQRuvNfbGh4QpQ",
"types" : [ "administrative_area_level_1", "political" ],
"url" : "https://maps.google.com/?q=Washington,+USA&ftid=0x5485e5ffe7c3b0f9:0x944278686c5ff3ba",
"utc_offset" : -480,
"website" : "http://www.access.wa.gov/"
},
"status" : "OK"
}

Artifactory API - List all artifacts for a package version

What's the best way to list all assets for a given package via the Artifactory API?
I'm trying to write a script to get the assets for a package and I'd like for it to work with multiple repository types, like Maven and PyPI. I know I could use the Folder Info API to get what I need, but that relies on the repository layout, so it wouldn't work across repository types.
I'm currently using this AQL search:
curl -u user:password -X POST http://<artifactory_url>/artifactory/api/search/aql \
-H "Content-Type: text/plain" \
-d 'items.find({"repo": "libs-release-local"}, {"artifact.module.name": "com.foo.bar:fizz-buzz:1.2"})'
The response is almost what I want, but it seems to be including some assets from a different version of the package I'm searching for:
{
"results" : [ {
"repo" : "libs-release-local",
"path" : "com/foo/bar/fizz-buzz/1.0",
"name" : "fizz-buzz-1.0.properties",
"type" : "file",
"size" : 790,
"created" : "2020-09-29T15:35:59.233Z",
"created_by" : "user",
"modified" : "2020-09-29T15:35:59.181Z",
"modified_by" : "user",
"updated" : "2020-09-29T15:35:59.233Z"
},{
"repo" : "libs-release-local",
"path" : "com/foo/bar/fizz-buzz/1.1",
"name" : "fizz-buzz-1.1.properties",
"type" : "file",
"size" : 790,
"created" : "2020-09-29T15:42:34.982Z",
"created_by" : "user",
"modified" : "2020-09-29T15:42:34.931Z",
"modified_by" : "user",
"updated" : "2020-09-29T15:42:34.983Z"
},{
"repo" : "libs-release-local",
"path" : "com/foo/bar/fizz-buzz/1.2",
"name" : "fizz-buzz-1.2-javadoc.jar",
"type" : "file",
"size" : 391843,
"created" : "2020-09-30T18:54:41.599Z",
"created_by" : "user",
"modified" : "2020-09-30T18:54:40.650Z",
"modified_by" : "user",
"updated" : "2020-09-30T18:54:41.600Z"
},{
"repo" : "libs-release-local",
"path" : "com/foo/bar/fizz-buzz/1.2",
"name" : "fizz-buzz-1.2-sources.jar",
"type" : "file",
"size" : 1089,
"created" : "2020-09-30T18:54:41.764Z",
"created_by" : "user",
"modified" : "2020-09-30T18:54:41.710Z",
"modified_by" : "user",
"updated" : "2020-09-30T18:54:41.765Z"
},{
"repo" : "libs-release-local",
"path" : "com/foo/bar/fizz-buzz/1.2",
"name" : "fizz-buzz-1.2.jar",
"type" : "file",
"size" : 1410,
"created" : "2020-09-30T18:54:41.902Z",
"created_by" : "user",
"modified" : "2020-09-30T18:54:41.844Z",
"modified_by" : "user",
"updated" : "2020-09-30T18:54:41.903Z"
},{
"repo" : "libs-release-local",
"path" : "com/foo/bar/fizz-buzz/1.2",
"name" : "fizz-buzz-1.2.module",
"type" : "file",
"size" : 3481,
"created" : "2020-09-30T18:54:42.015Z",
"created_by" : "user",
"modified" : "2020-09-30T18:54:41.962Z",
"modified_by" : "user",
"updated" : "2020-09-30T18:54:42.015Z"
},{
"repo" : "libs-release-local",
"path" : "com/foo/bar/fizz-buzz/1.2",
"name" : "fizz-buzz-1.2.pom",
"type" : "file",
"size" : 781,
"created" : "2020-09-30T18:54:42.238Z",
"created_by" : "user",
"modified" : "2020-09-30T18:54:42.190Z",
"modified_by" : "user",
"updated" : "2020-09-30T18:54:42.238Z"
},{
"repo" : "libs-release-local",
"path" : "com/foo/bar/fizz-buzz/1.2",
"name" : "fizz-buzz-1.2.properties",
"type" : "file",
"size" : 790,
"created" : "2020-09-30T18:54:42.124Z",
"created_by" : "user",
"modified" : "2020-09-30T18:54:42.078Z",
"modified_by" : "user",
"updated" : "2020-09-30T18:54:42.125Z"
} ],
"range" : {
"start_pos" : 0,
"end_pos" : 8,
"total" : 8
}
}
Notice how it's including the properties file for fizz-buzz 1.0 and 1.1, even though I specified 1.2 in my search.
Is there a better way to get the information I'm looking for?
You can use the new GraphQL capability which was added in Artifactory 7.9.
This new capability allows you to query the rich metadata Artifactory holds about packages, version, artifacts and more using the GraphQL query language.
You can use the metadata REST API for queries. Please notice you need to use an admin access token for authentication. For example:
curl -H "Authorization: Bearer <Your Token>" -XPOST http://localhost:8082/metadata/api/v1/query -d '{"query":"..." }'
The following query, as an example, is fetching all the files which are part of versions 1.0* of a package named hello-world. This query will work for any type of package which can be managed in Artifactory.
query {
packages(
filter: {
name: "hello-world"
}
) {
edges {
node {
name
packageType
versions (filter: {name : "1.0*"}) {
name
repos {
name
leadFilePath
}
files {
name
}
}
}
}
}
}
The result would look something like
{
"data": {
"packages": {
"edges": [
{
"node": {
"name": "hello-world",
"packageType": "maven",
"versions": [
{
"name": "1.0-SNAPSHOT",
"repos": [
{
"name": "kotlin-local-snapshots",
"leadFilePath": "org/jetbrains/kotlin/hello-world/1.0-SNAPSHOT/hello-world-1.0-20171225.112927-1.pom"
}
],
"files": [
{
"name": "hello-world-1.0-20171225.112927-1.jar"
},
{
"name": "hello-world-1.0-20171225.112927-1.pom"
}
]
}
]
}
},
{
"node": {
"name": "hello-world",
"packageType": "maven",
"versions": [
{
"name": "1.0-SNAPSHOT",
"repos": [
{
"name": "kotlin-local-snapshots",
"leadFilePath": "org/jetbrains/kotlin/examples/hello-world/1.0-SNAPSHOT/hello-world-1.0-20171225.112138-1.pom"
}
],
"files": [
{
"name": "hello-world-1.0-20171225.112138-1.jar"
},
{
"name": "hello-world-1.0-20171225.112138-1.pom"
}
]
}
]
}
}
]
}
}
}
Try the below its using the path to only find artifacts that match com/foo/bar/fizz-buzz in the repo libs-release-local and then some jq at the end to make the output better. Noticed also the type : file which eliminates some noise in terms of metdata.
You will need to define or replace USER, API_KEY, and ARTIFACTORY_URL.
curl -su "${USER}:${API_KEY}" -X POST "${ARTIFACTORY_URL}/artifactory/api/search/aql" \
-H "content-type: text/plain" \
-d "items.find({\"type\" : \"file\",\"\$and\":[{\"path\" : {\"\$match\" : \"com/foo/bar/fizz-buzz*\"}, \"repo\" : {\"\$match\" : \"libs-release-local\"} }]}).include(\"name\",\"repo\",\"path\",\"size\").sort({\"\$desc\": [\"size\"]})" \
| jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" | grep results | cut -f 2 -d = | jq .

Elasticsearch low indexing speed

I have a blog that contains 14k posts and tried to add these posts to the elastic search index.
I indexed some of the posts, but it's extremely slow, and it will take about 6 hours to estimate. All the performance optimization tips from the official site I made. In my opinion, I removed the redundant data such as post meta. Can I increase indexing speed? Add the index configuration below:
{
"test-post-1" : {
"aliases" : { },
"mappings" : {
"date_detection" : false,
"properties" : {
"ID" : {
"type" : "long"
},
"guid" : {
"type" : "keyword"
},
"menu_order" : {
"type" : "long"
},
"permalink" : {
"type" : "keyword"
},
"post_content" : {
"type" : "text"
},
"post_date" : {
"type" : "date",
"format" : "yyyy-MM-dd HH:mm:ss"
},
"post_excerpt" : {
"type" : "text"
},
"post_id" : {
"type" : "long"
},
"post_mime_type" : {
"type" : "keyword"
},
"post_modified" : {
"type" : "date",
"format" : "yyyy-MM-dd HH:mm:ss"
},
"post_name" : {
"type" : "text",
"fields" : {
"post_name" : {
"type" : "text"
},
"raw" : {
"type" : "keyword",
"ignore_above" : 10922
}
}
},
"post_parent" : {
"type" : "long"
},
"post_status" : {
"type" : "keyword"
},
"post_title" : {
"type" : "text",
"fields" : {
"post_title" : {
"type" : "text",
"analyzer" : "standard"
},
"raw" : {
"type" : "keyword",
"ignore_above" : 10922
},
"sortable" : {
"type" : "keyword",
"ignore_above" : 10922,
"normalizer" : "lowerasciinormalizer"
}
}
},
"post_type" : {
"type" : "text",
"fields" : {
"post_type" : {
"type" : "text"
},
"raw" : {
"type" : "keyword"
}
}
}
}
},
"settings" : {
"index" : {
"mapping" : {
"total_fields" : {
"limit" : "5000"
},
"ignore_malformed" : "true"
},
"number_of_shards" : "1",
"provided_name" : "test-post-1",
"max_shingle_diff" : "8",
"max_result_window" : "1000000",
"creation_date" : "1582745447768",
"analysis" : {
"filter" : {
"shingle_filter" : {
"max_shingle_size" : "5",
"min_shingle_size" : "2",
"type" : "shingle"
},
"edge_ngram" : {
"min_gram" : "3",
"side" : "front",
"type" : "edgeNGram",
"max_gram" : "10"
},
"ewp_word_delimiter" : {
"type" : "word_delimiter",
"preserve_original" : "true"
},
"ewp_snowball" : {
"type" : "snowball",
"language" : "russian"
}
},
"normalizer" : {
"lowerasciinormalizer" : {
"filter" : [
"lowercase",
"asciifolding"
],
"type" : "custom"
}
},
"analyzer" : {
"ewp_lowercase" : {
"filter" : [
"lowercase"
],
"type" : "custom",
"tokenizer" : "keyword"
},
"shingle_analyzer" : {
"filter" : [
"lowercase",
"shingle_filter"
],
"type" : "custom",
"tokenizer" : "standard"
},
"default" : {
"filter" : [
"ewp_word_delimiter",
"lowercase",
"stop",
"ewp_snowball"
],
"char_filter" : [
"html_strip"
],
"language" : "russian",
"tokenizer" : "standard"
}
}
},
"number_of_replicas" : "1",
"uuid" : "cWGjSF4FQ1Or0A_0oSlA2g",
"version" : {
"created" : "7050299"
}
}
}
}
}
Wordpress version: 5.3.2
Elasticsearch version: 7.5.2
Enabled plugins: ElasticPress

meteor sort find() how?

I would like to make a ToDo list webapp in meteor, where users could define their own goals and sort them, so the higher a goal is, the bigger it's priority becomes.
I have two Collections:
meteor:PRIMARY> db.goals.find()
{ "_id" : "ZDCwfD4pWfD7sZ9DB", "gtext" : "Money", "createdAt" : ISODate("2015-12-26T13:15:59.563Z"), "owner" : "qDqGDaXjaHXNhX95u", "username" : "prsz", "order" : 0 }
{ "_id" : "B9oKRGssNWhjz57dP", "gtext" : "Procrastination", "createdAt" : ISODate("2015-12-26T13:16:06.272Z"), "owner" : "qDqGDaXjaHXNhX95u", "username" : "prsz", "order" : 3 }
{ "_id" : "famqG5vby9wBo37Ns", "gtext" : "Housework", "createdAt" : ISODate("2016-01-01T15:01:02.256Z"), "owner" : "qDqGDaXjaHXNhX95u", "username" : "prsz", "order" : 2 }
{ "_id" : "QKWJjTEwZQs5ErrPR", "gtext" : "Getting fit", "createdAt" : ISODate("2016-01-01T16:10:38.302Z"), "owner" : "qDqGDaXjaHXNhX95u", "username" : "prsz", "order" : 1 }
{ "_id" : "ByNyg9uRBH35XXgdi", "gtext" : "test1", "createdAt" : ISODate("2016-01-06T13:40:15.224Z"), "owner" : "JWdrC3bFgmHXHeDFf", "order" : 0 }
meteor:PRIMARY> db.tasks.find()
{ "_id" : "gNuyxHdyA6HN8JFsd", "text" : "clean up", "createdAt" : ISODate("2015-12-27T11:12:46.186Z"), "owner" : "qDqGDaXjaHXNhX95u", "username" : "prsz", "notes" : "", "priority" : "famqG5vby9wBo37Ns", "postponedate" : "", "checked" : false, "relatedgoal": { "order": 2, "_id": "famqG5vby9wBo37Ns" }}
{ "_id" : "6dEkaETWAkhsELP8r", "text" : "Sell something", "createdAt" : ISODate("2015-12-27T11:12:48.669Z"), "owner" : "qDqGDaXjaHXNhX95u", "username" : "prsz", "notes" : "", "priority" : "ZDCwfD4pWfD7sZ9DB", "postponedate" : "", "relatedgoal": { "order": 0, "_id": "ZDCwfD4pWfD7sZ9DB"} }
{ "_id" : "nCKz9oCkiExz4ekfK", "text" : "Win the lottery", "createdAt" : ISODate("2015-12-27T11:12:51.294Z"), "owner" : "qDqGDaXjaHXNhX95u", "username" : "prsz", "notes" : "", "priority" : "ZDCwfD4pWfD7sZ9DB", "postponedate" : "", "relatedgoal": { "order": 0, "_id": "ZDCwfD4pWfD7sZ9DB" } }
{ "_id" : "YvWxaxWM9qvGzkpEK", "text" : "read a magazine", "createdAt" : ISODate("2015-12-27T11:12:41.526Z"), "owner" : "qDqGDaXjaHXNhX95u", "username" : "prsz", "notes" : "", "priority" : "B9oKRGssNWhjz57dP", "postponedate" : "" "relatedgoal": { "order": 3, "_id": "B9oKRGssNWhjz57dP" }}
{ "_id" : "s53vn9tf8C5tyy27q", "text" : "task1", "createdAt" : ISODate("2016-01-06T13:39:36.673Z"), "owner" : "JWdrC3bFgmHXHeDFf", "notes" : "", "priority" : "ByNyg9uRBH35XXgdi", "postponedate" : "" }
{ "_id" : "bEWosRJK4ekAvSuJ6", "text" : "do some situps", "createdAt" : ISODate("2016-01-08T15:47:41.047Z"), "owner" : "qDqGDaXjaHXNhX95u", "username" : "prsz", "notes" : "", "priority" : "QKWJjTEwZQs5ErrPR", "relatedgoal": { "order": 1, "_id": "QKWJjTEwZQs5ErrPR" }}
My ultimate goal is to be able to sort the tasks by the order field of the related goal.
I'm using perak/meteor-joins to join the tasks collection with the related goal's oder field.
Now my problem is that I cannot get my find() to sort the goals by the oder field.
client.js:
Meteor.subscribe('Tasks');
Meteor.subscribe('Goals');
Template.body.helpers({
priorityTasks: function() {
return Tasks.find(
{postponedate: {$exists: false }},
{sort: {'relatedgoal.order': -1}}
)
}
});
I even tried, this but did not help either:
priorityTasks: function() {
return Tasks.find(
{postponedate: {$exists: false }},
{sort: {relatedgoal.order: 1}}
)
}),
Is there a way to sort the tasks by their order field?
I was thinking about a transform in the find method, but that's not reactive. I need a reactive solution.
Server.js:
Tasks = new Mongo.Collection("tasks");
Goals = new Mongo.Collection("goals");
Tasks.join(Goals, "priority", "relatedgoal", ["order"]);
Meteor.publish('Tasks',function() {
return Tasks.find({ owner: this.userId});
});
Meteor.publish('Goals',function() {
return Goals.find({ owner: this.userId});
});
Sortable.collections = ['goals'];
todo.html
<div class="container-fluid col-md-6">
<ul>
{{#each priorityTasks}}
{{> task}}
{{/each}}
</ul>
</div>
<template name="task">
<li>
<span class="text">
<a href="#modal-5" data-toggle="modal">
<strong>{{text}} - {{relatedgoal.order}}</strong>
</a>
<br>
{{postponedate}}
</span>
</li>
</template>
priorityTasks: function() {
return Tasks.find(
{
postponedate: {$exists: false }
}, {
sort: {'relatedgoal.order': 1}})
},
should work

querying elasitcsearch parent child documents

We work with two types of documents on elastic search (ES): items and slots, where items are parents of slot documents.
We define the index with the following command:
curl -XPOST 'localhost:9200/items' -d #itemsdef.json
where itemsdef.json has the following definition
{
"mappings" : {
"item" : {
"properties" : {
"id" : {"type" : "long" },
"name" : {
"type" : "string",
"_analyzer" : "textIndexAnalyzer"
},
"location" : {"type" : "geo_point" },
}
}
},
"settings" : {
"analysis" : {
"analyzer" : {
"activityIndexAnalyzer" : {
"alias" : ["activityQueryAnalyzer"],
"type" : "custom",
"tokenizer" : "whitespace",
"filter" : ["trim", "lowercase", "asciifolding", "spanish_stop", "spanish_synonym"]
},
"textIndexAnalyzer" : {
"type" : "custom",
"tokenizer" : "whitespace",
"filter" : ["word_delimiter_impl", "trim", "lowercase", "asciifolding", "spanish_stop", "spanish_synonym"]
},
"textQueryAnalyzer" : {
"type" : "custom",
"tokenizer" : "whitespace",
"filter" : ["trim", "lowercase", "asciifolding", "spanish_stop"]
}
},
"filter" : {
"spanish_stop" : {
"type" : "stop",
"ignore_case" : true,
"enable_position_increments" : true,
"stopwords_path" : "analysis/spanish-stopwords.txt"
},
"spanish_synonym" : {
"type" : "synonym",
"synonyms_path" : "analysis/spanish-synonyms.txt"
},
"word_delimiter_impl" : {
"type" : "word_delimiter",
"generate_word_parts" : true,
"generate_number_parts" : true,
"catenate_words" : true,
"catenate_numbers" : true,
"split_on_case_change" : false
}
}
}
}
}
Then we add the child document definition using the following command:
curl -XPOST 'localhost:9200/items/slot/_mapping' -d #slotsdef.json
Where slotsdef.json has the following definition:
{
"slot" : {
"_parent" : {"type" : "item"},
"_routing" : {
"required" : true,
"path" : "parent_id"
},
"properties": {
"id" : { "type" : "long" },
"parent_id" : { "type" : "long" },
"activity" : {
"type" : "string",
"_analyzer" : "activityIndexAnalyzer"
},
"day" : { "type" : "integer" },
"start" : { "type" : "integer" },
"end" : { "type" : "integer" }
}
}
}
Finally we perform a bulk index with the following command:
curl -XPOST 'localhost:9200/items/_bulk' --data-binary #testbulk.json
Where testbulk.json holds the following data:
{"index":{"_type": "item", "_id":35}}
{"location":[40.4,-3.6],"id":35,"name":"A Name"}
{"index":{"_type":"slot","_id":126,"_parent":35}}
{"id":126,"start":1330,"day":1,"end":1730,"activity":"An Activity","parent_id":35}
I'm trying to make the following query: search for all items within a certain distance to a location that have children (slots) in the specified days and within certain start and end ranges.
An item with more slots fulfilling the condition should score higher.
I tried starting with existing samples but the docs are really scarce and its hard to move forward.
Clues?
I don't think there is a way to write an efficient query that would do something like this without moving location to slots. You can do something like this, but it can quite inefficient for some data:
{
"query": {
"top_children" : {
"type": "blog_tag",
"query" : {
"constant_score" : {
"query" : {
... your query for children goes here ...
}
}
},
"score" : "sum",
"factor" : 5,
"incremental_factor" : 2
}
},
"filter": {
"geo_distance" : {
"distance" : "200km",
"location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
Basically, what this query is doing is this, it takes your range query or filter for children and whatever other conditions you need and wraps it into constant_score query to make sure that all children have score of 1.0. The top_children query collects all these children and accumulates their scores to the parents. And then filter filters out parents that are too far away.

Resources