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
Related
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
I'm trying to create a rule that allows some users to write but not all.
I need that all user can read 'menu' items but only users listed at store data can write.
My data structure:
{
"category" : [ null, "Burger", "Drinks" ],
"menu" : [ null, {
"available" : true,
"category" : "1",
"description" : "item1 description",
"image" : "chicken_maharaja",
"name" : "New Chicken Maharaja",
"price" : 1300,
"store" : 1
}, {
"available" : true,
"category" : "1",
"description" : "item2 description",
"image" : "big_spicy_chicken_wrap",
"name" : "Big Spicy Chicken Wrap",
"price" : 120,
"store" : 1
}, {
"available" : true,
"category" : "2",
"description" : "item3 description",
"image" : "thumsup",
"name" : "Thumsup 100ml",
"price" : 40,
"store" : 1
}, {
"available" : true,
"category" : "2",
"description" : "item4 description",
"image" : "mccafe_ice_coffee",
"name" : "Ice Coffee",
"price" : 140,
"store" : 1
}, {
"available" : true,
"category" : "1",
"description" : "item5 description",
"image" : "mc_chicken",
"name" : "MC Chicken",
"price" : 190,
"store" : 1
}, {
"available" : true,
"category" : "2",
"description" : "item6 description",
"image" : "Smoothie",
"name" : "Smoothie",
"price" : 70,
"store" : 2
}, {
"available" : true,
"category" : "1",
"description" : "item8 description",
"image" : "salad_wrap",
"name" : "Salad Wrap",
"price" : 150,
"store" : 2
} ],
"stores" : [ null, {
"location" : "Campinas - Taquaral",
"name" : "Store 1",
"user" : {
"pyixsRTw9qdiuESt62YnmEYXQt13" : true
}
}, {
"location" : "São Paulo - Perdises",
"name" : "Store 2",
"user" : {
"LBNZ8Dwp2rdJtlSh0NC1ApdtbAl2" : true,
"TLomOgrd3gbjDdpDAqGiwl0lBhn2" : true
}
} ],
"userProfile" : {
"LBNZ8Dwp2rdJtlSh0NC1ApdtbAl2" : {
"birthDate" : "1974-02-10",
"email" : "asd#asd.com",
"firstName" : "João",
"lastName" : "Silva"
},
"pyixsRTw9qdiuESt62YnmEYXQt13" : {
"birthDate" : "1974-02-10",
"email" : "leandro.garcias#gmail.com",
"firstName" : "Leandro",
"lastName" : "Garcia"
}
}
}
My rule:
{
"rules": {
"menu": {
"$items": {
".read": "true",
".write": "root.child('stores').child('1').child(data.child('user').val()).hasChild(auth.uid)"
}
},
"stores": {
"$store": {
".read": "true",
".write": "root.child('stores').child('$store').child(data.child('user').val()).hasChild(auth.uid)"
}
}
}
}
The read is ok. :-) But I can't write.
Your newData doesn't have a child user so that check always fails. You probably mean:
"43268522": {
"menu": {
"$items": {
".read": "true",
".write": "root.child('stores').child('1').child('user').hasChild(auth.uid)"
}
}
You're probably looking for this rule:
".write": "
root.child('stores')
.child(newData.child('store').val())
.child('user')
.hasChild(auth.uid)"
So this uses the store property from the new data to look up if the current user is in the store they're trying to modify.
Unfortunately this rule won't work with your current data structure, since the value of store is a number, while the key of a store is a string: "1" !== 1.
The simplest solution is to store the store as a string, e.g.:
"store": "1"
You might want to consider that anyway, since you're now getting Firebase's array coercion, which is not helpful. For more on this see our blog post on Best Practices: Arrays in Firebase. I'd recommend storing stores using either push IDs, or simply prefixing them, e.g.
"stores": {
"store1": {
...
}
}
I am wondering if it's possible to do the firebase authentication on strings? I have seen it being done on keys like -XDhabsuduydvtest <- random test key.
Now i have this structure:
{
"conversations" : {
"person1" : {
"person2" : {
"0" : 0,
"last_read" : 1460377167535
}
},
"person2" : {
"person1" : {
"0" : 0,
"last_read" : 1460377125515
}
}
},
"messages" : {
"eb-uuid-729fc0ac-49b8-48fa-a2ff-f2ada67b9e4c-person1" : {
"body" : "Dit is een test vanuit iOS",
"date" : 1460383996536,
"sender" : "eb-uuid-729fc0ac-49b8-48fa-a2ff-f2ada67b9e4c"
},
"person1-person2" : {
"-KF49xHKqnDawywJ9H0b" : {
"body" : "test message",
"date" : 1460375639190,
"sender" : "person1"
},
"-KF4Fc1KHH31O4_l0QWh" : {
"body" : "new",
"date" : 1460377125013,
"sender" : "person2"
}
}
},
"users" : {
"eb-uuid-729fc0ac-49b8-48fa-a2ff-f2ada67b9e4c" : {
"chat_enabled" : true,
"email" : "test#gmail.com",
"first_name" : "John",
"last_name" : "Smith",
"provider" : "password",
"push_muted" : false,
"push_token" : "some-push-token",
"uid" : "729fc0ac-49b8-48fa-a2ff-f2ada67b9e4c",
"username" : "johnsmith"
},
"person1" : {
"first_name" : "person",
"last_name" : "one"
},
"person2" : {
"first_name" : "person",
"last_name" : "two"
}
}
}
plus some security rule i tried, obviously i'd like to check if the uuid's are the same, and not only if one exists
{
"rules": {
"messages": {
"$conv":{
//Person can only read a conversation he/she is participating in
".write": true,
".read": true,
".indexOn": ["date"]
}
},
"users":{
"$ebuuid":{
".write": "root.child('users').child($ebuuid).hasChild('uid')",
".read": "root.child('users').child($ebuuid).hasChild('uid')"
}
},
"conversations":{
".write": "data.child('uid').val() === auth.uid",
".read": true
}
}
}
(Replaced images with text)
I'm really not sure how to go from here now .. the user has some uid but i'm not sure how to check it with whether he or she can post messages etc ..
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
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.