Skip to content

Instantly share code, notes, and snippets.

@Lackoftactics
Last active June 26, 2017 10:29
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 Lackoftactics/a8503c5cb75eff8667023d4003d12cbc to your computer and use it in GitHub Desktop.
Save Lackoftactics/a8503c5cb75eff8667023d4003d12cbc to your computer and use it in GitHub Desktop.
Elasticsearch
curl -X PUT localhost:9200/books -d '
{
"settings" : {
"index" : {
"analysis" : {
"analyzer" : {
"autocomplete_analyzer" : {
"type" : "custom",
"tokenizer" : "lowercase",
"filter" : ["asciifolding", "title_ngram"]
}
},
"filter" : {
"title_ngram" : {
"type" : "nGram",
"min_gram" : 3,
"max_gram" : 5
}
}
}
}
},
"mappings": {
"title": {
"properties": {
"title": {
"type": "string",
"analyzer": "autocomplete_analyzer"
}
}
}
}
}
'
curl "http://localhost:9200/books/_search?q=title=The"
Using cross fields
curl localhost:9200/books/_search -d '
{
"query": {
"multi_match": {
"query": "Witness western",
"type": "cross_fields",
"fields": ["title^2", "genre"]
}
}
}
'
Boosting fields
Boost books which have classic genre
curl localhost:9200/books/_search -d '
{
"query": {
"bool": {
"must": {
"match": {
"title": {
"query": "Trees",
"operator": "and"
}
}
},
"should": [
{ "match": {
"genre": {
"query": "crime",
"boost": 3
}
}}
]
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment