Skip to content

Instantly share code, notes, and snippets.

@KunihikoKido
KunihikoKido / dictsort.py
Created August 2, 2013 02:55
Python 辞書型のソート
def dictsorted(dic, valuesort=False):
if valuesort:
return [(k, v) for k, v in sorted(d.items(), key=lambda x:x[1])]
return [(k, v) for k, v in sorted(d.items())]
if __name__ == '__main__':
d = {'A':500, 'C':300, 'D':100, 'E':400, 'B':200}
print dictsorted(d, False)
print dictsorted(d, True)
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
@KunihikoKido
KunihikoKido / japanese_template.json
Last active April 2, 2020 04:12
Elasticsearch - Dynamic Mapping for Japanese
{
"japanese_template": {
"template": "*ja",
"settings": {
"analysis": {
"filter": {
"romaji": {
"type": "kuromoji_readingform",
"use_romaji": true
}
@KunihikoKido
KunihikoKido / gist:0a3df0038f7e736c1812
Last active August 29, 2015 14:04
Medium Hello Elasticsearch import data
curl -XPUT 'localhost:9200/medium/blog/1' -d '{
"title": "Elasticsearch 特徴まとめ",
"description": "Elasticsearch Features — 主にシステムを中心とした特徴まとめ",
"creator": "Kunihiko Kido",
"link": "https://medium.com/hello-elasticsearch/elasticsearch-500996e47c70",
"tags": ["Elasticsearch"],
"pubDate": "2014-03-12T11:09"
}'
curl -XPUT 'localhost:9200/medium/blog/2' -d '{

##alt text GistList: TODO for coders alt text

# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
import json
import boto3
import logging
from elasticsearch import Elasticsearch
from elasticsearch import helpers
from elasticsearch.exceptions import ElasticsearchException
{
"category": "サッカー",
"query": {
"bool": {
"should": [{
"simple_query_string": {
"fields": ["text"],
"default_operator": "or",
"query": "\"サッカー\" "
}
{
"took": 8883,
"timed_out": false,
"_shards": {
"total": 90,
"successful": 90,
"failed": 0
},
"hits": {
"total": 2811,
{
"query": {
"bool": {
"must": [{
"simple_query_string": {
"query": "\"サッカー\"", // 1) 人が与える任意の分類・キーワード
"fields": ["text"] // 2) 検索対象フィールド
}
}],
"filter": [{
{
"doc": {
"text": "スターウォーズのスター・デストロイヤー型ドローン動画が話題に"
},
"aggs": {
"categories": {
"terms": {
"field": "category"
}
}