Created
October 3, 2012 13:44
-
-
Save adrienjoly/3826977 to your computer and use it in GitHub Desktop.
Spotify-like search/filter using ElasticSearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to store in ./config | |
index: | |
analysis: | |
analyzer: | |
full_text_analyzer: | |
type: custom | |
tokenizer: standard | |
filter: [standard, lowercase, asciifolding] | |
partial_text_analyzer : | |
type : custom | |
tokenizer : standard | |
filter : [standard, lowercase, asciifolding, my_edge_ngram] | |
filter : | |
my_edge_ngram : | |
type : edgeNGram | |
min_gram : 1 | |
max_gram : 10 | |
side : front |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* to store in ./config/templates */ | |
{ | |
"my_template" : { | |
"template" : "*", | |
"settings" : {}, | |
"mappings" : { | |
"_default_" : { | |
"properties": { | |
"uid": { | |
"type": "string", | |
"index": "not_analyzed", | |
"include_in_all": false | |
}, | |
"title": { | |
"type": "multi_field", | |
"fields": { | |
"title": { | |
"type": "string", | |
"index_analyzer": "partial_text_analyzer", | |
"search_analyzer": "full_text_analyzer", | |
"boost": 1 | |
}, | |
"full": { | |
"type": "string", | |
"analyzer": "full_text_analyzer", | |
"boost": 10 | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
elasticsearch -f -Xmx2g -Xms2g -Des.config=config/elasticsearch.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# curl -XDELETE 'http://localhost:9200/myIndex/' | |
# curl -XPUT 'http://localhost:9200/_bulk' --data-binary @myIndex.json | |
curl -XPUT 'http://localhost:9200/myIndex/post/' -d '{ | |
"title" : "hello world", | |
"uId" : "001" | |
}' | |
curl -XGET 'http://localhost:9200/myIndex/post/' -d '{ | |
"query": { | |
"filtered": { | |
"query":{ | |
"match": { | |
"title": { | |
"query": "hell wor", | |
"operator": "AND" | |
} | |
} | |
}, | |
"filter": { "uId": "001" } | |
} | |
}, | |
"from": q.from || 0, | |
"size": q.from || 50, | |
"sort": q.sort || [{'_score': 'desc'}], | |
"facets": q.facets || {} | |
}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment