Skip to content

Instantly share code, notes, and snippets.

View loren's full-sized avatar

Loren Siebert loren

View GitHub Profile
@loren
loren / rails_routing_invalid_chars_fix.rb
Created August 17, 2012 17:37
Fix for ArgumentError: invalid byte sequence in UTF-8
require 'action_dispatch/routing/route_set'
# Based on https://gist.github.com/2830082
module ActionDispatch
module Routing
class RouteSet
class Dispatcher
def call_with_invalid_char_handling(env)
uri = CGI::unescape(env["REQUEST_URI"].force_encoding("UTF-8"))
# If anything in the REQUEST_URI has an invalid encoding, then raise since it's likely to trigger errors further on.
return [400, {'X-Cascade' => 'pass'}, []] if uri.is_a?(String) and !uri.valid_encoding?
@loren
loren / allow_unmapped_fields.sh
Created November 11, 2014 06:46
index.query.parse.allow_unmapped_fields setting does not seem to allow unmapped fields in alias filters
# verify we are allowing unmapped fields
curl -s -XGET '/_nodes?pretty=true' | grep allow_unmapped
# "allow_unmapped_fields" : "true"
# delete the index
curl -XDELETE 127.0.0.1:9200/test1
# create index with explicit mapping only for user field
curl -XPUT 127.0.0.1:9200/test1 -d '
{
@loren
loren / en.yml
Created November 7, 2014 13:07
English-only synonyms
tenth, 10th:
note: Added and approved ordinal number set. AFF 10/7/14
status: Approved
ninth, 9th:
note: Added and approved ordinal number set. AFF 10/7/14
status: Approved
@loren
loren / synonyms.yml
Created November 7, 2014 13:05
Possible YAML format for all synonyms (English+Spanish combined)
tenth, 10th:
locale: English
note: Added and approved ordinal number set. AFF 10/7/14
status: Approved
visas, visa:
locale: Spanish
note: Approved AFF 2/6/14.
status: Approved
@loren
loren / top_hits.json
Created October 29, 2014 15:17
Top image hits from each album
{
"aggs": {
"album_agg": {
"terms": {
"field": "album",
"order": {
"top_score": "desc"
}
},
"aggs": {
@loren
loren / more_like_this.json
Created October 29, 2014 15:16
More like this (MLT) query to group/classify photos into albums
GET http://localhost:9200/development-asis-flickr_photos/_search
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"more_like_this": {
"fields": [
@loren
loren / spelling.json
Created October 29, 2014 15:14
Spelling suggestion based on bigram field
{
"suggest": {
"text": "jeferson memorial",
"suggestion": {
"phrase": {
"analyzer": "bigram_analyzer",
"field": "bigram",
"size": 1,
"direct_generator": [
{
@loren
loren / second_instagram_mapping.json
Created October 29, 2014 15:13
Second iteration on Instagram mapping for Elasticsearch
{
"properties": {
"bigram": {
"type": "string",
"analyzer": "bigram_analyzer"
},
"caption": {
"type": "string",
"analyzer": "en_analyzer",
"copy_to": [
@loren
loren / second_flickr_mapping.json
Created October 29, 2014 15:12
Second iteration on Flickr mapping for Elasticsearch
{
"properties": {
"bigram": {
"type": "string",
"analyzer": "bigram_analyzer"
},
"description": {
"type": "string",
"analyzer": "en_analyzer",
"copy_to": [
@loren
loren / match_phrase.json
Created October 29, 2014 15:09
Recognize proximity of words
{
"bool": {
"should": [
{
"match": {
"tags": {
"query": "jefferson memorial",
"analyzer": "tag_analyzer"
}
}