Skip to content

Instantly share code, notes, and snippets.

@athoune
Created January 17, 2012 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athoune/1629799 to your computer and use it in GitHub Desktop.
Save athoune/1629799 to your computer and use it in GitHub Desktop.
trouble with multi_field with tire
#encoding: utf-8
require 'rubygems'
require 'tire'
#require 'json'
require 'active_support/core_ext/object/to_query'
require 'active_support/core_ext/object/to_param'
Tire.configure { logger 'elasticsearch.log', :level => 'debug' }
tire = Tire.index 'path' do
delete
conf = {
settings: {
analysis: {
tokenizer: {
my_path_tokenizer: {
type: 'path_hierarchy',
delimiter: '.'
}
},
analyzer: {
my_path: {
type: 'custom',
tokenizer: 'my_path_tokenizer',
filter: ['lowercase']
},
my_tokens: {
type: 'pattern',
pattern: '[.]'
}
}
}
},
mappings: {
key: {
properties: {
key: {
type: 'multi_field',
fields: {
raw: {
type: 'string',
analyzer: 'keyword',
include_in_all: false
},
key: { # see https://gist.github.com/1042483
type: 'string',
analyzer: 'my_tokens',
include_in_all: true
},
path: {
type: 'string',
analyzer: 'my_path',
include_in_all: true
}
}
}
}
}
}
}
create conf
import %w{worg.elasticsearch.info org.elasticsearch.src org.lucene.info}.map{|key| {id: key, key: key, type:'key'} }
refresh
end
p 'path', tire.analyze("org.elasticsearch.info", analyzer: 'my_path')['tokens'].map{|token| token['token']}
p 'tokens', tire.analyze("org.elasticsearch.info", analyzer: 'my_tokens')['tokens'].map{|token| token['token']}
s = Tire.search 'path' do
query do
string 'key:elasticsearch'
end
end
p "search key:elasticsearch", s.results.length
# 1
s = Tire.search 'path' do
query do
string 'elasticsearch'
end
end
p "search elasticsearch", s.results.length
# 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment