Skip to content

Instantly share code, notes, and snippets.

View darklow's full-sized avatar

Kaspars Sprogis darklow

View GitHub Profile
// mapping
{
"credits": {
"properties": {
"position": {
"type": "integer"
},
"person": {
"properties": {
"id": {
@darklow
darklow / es_completion_suggest.sh
Last active December 21, 2015 14:09
Testing completion suggest in ElasticSearch
#!/bin/bash
# ========================================
# Testing completion suggest in ElasticSearch
# ========================================
curl -X DELETE localhost:9200/hotels
curl -X PUT localhost:9200/hotels -d '
{
"mappings": {
"hotel" : {
// in older versions, for getting model from different controller i was using:
App.FoodController = Em.ArrayController.extend({
addFood: function (food) {
var items = this.controllerFor('table').get('model').get('tab.tabItems');
tabItems.createRecord({
food: food
})
}
});
@darklow
darklow / fabfile.py
Last active December 22, 2015 17:49
Django local server deployment with Fabric and virtualenv
from fabric.api import lcd, local, path
project_dir = '/www/project/sms/'
env_bin_dir = project_dir + '../env/bin'
def deploy():
with lcd(project_dir):
local('pwd')
local('git pull origin')
@darklow
darklow / elasticsearch.custom.sort.py
Last active May 31, 2022 05:25
ElasticSearch custom sort, based on provided ids array order. Original code from here: http://damienalexandre.fr/post/elasticsearch-ids-query-order Rewritten to new "function_score" syntax Note: You need to remove \n new lines from "script" field in order to get it work.
q = {
"query": {
"function_score": {
"boost_mode": "replace",
"query": {
"ids": {
"values": [
50,
80,
44,
@darklow
darklow / es_simple_analyzer.sh
Last active December 26, 2015 12:19
ElasticSearch simple analyzer test
#!/bin/bash
# ========================================
# Testing simple analyzer in ElasticSearch
# ========================================
curl -X DELETE localhost:9200/hotels
curl -X PUT localhost:9200/hotels -d '
{
"index": {
"analysis": {
@darklow
darklow / TagTrans.php
Last active December 31, 2015 02:09
Koken translation tag. <koken:trans en="Hello" fr="Bonjour" lv="Sveiki" />
<?php
class TagTrans extends Tag {
function generate()
{
$value = '""';
$lng = isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en';
if(isset($this->parameters[$lng])){
$value = '"' . $this->attr_parse($this->parameters[$lng]) . '"';
@darklow
darklow / es_nested_facets_filter.sh
Last active December 31, 2015 07:59
Nested facets filtering by parent in ElasticSearch
#!/bin/bash
# ========================================
# Nested facets filtering by parent in ElasticSearch
# --------------------------------------------------
# I need to get facets of departments for specific person for one movie genre:
# facets for credit.department where genre=comedy, credits.person_id=1
# I am using include_in_parent:true mapping to be able to facet_filter by parent genre
# ========================================
curl -X DELETE localhost:9200/movies
@darklow
darklow / es_aggs_nested.sh
Last active June 19, 2017 06:31
New aggregation framework - filtering by nested object fields
#!/bin/bash
# ========================================
curl -X DELETE localhost:9200/movies
curl -X PUT localhost:9200/movies -d '
{
"mappings": {
"movie": {
"properties": {
"name": { "type": "string" },
curl -XGET "http://localhost:9200/movies/_search" -d'
{
"query": {
"nested": {
"path": "credits",
"query": {
"match": {
"credits.person_id": 1
}
}