Forked from imotov/elasticsearch-filter-boosting-based-on-field-value.sh
Created
December 5, 2015 13:36
-
-
Save abhiesa-tolexo/38dcc9419ecd0bc8f646 to your computer and use it in GitHub Desktop.
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 localhost:9200/test-idx | |
echo | |
curl -XPUT localhost:9200/test-idx -d '{ | |
"settings": { | |
"index": { | |
"number_of_shards": 1, | |
"number_of_replicas": 0, | |
"analysis": { | |
"analyzer": { | |
"query_default": { | |
"type": "standard" | |
} | |
} | |
} | |
} | |
}, | |
"mappings": { | |
"doc": { | |
"properties": { | |
"title": {"type": "string", "index": "analyzed"}, | |
"description": {"type": "string", "index": "analyzed"}, | |
"format": {"type": "string", "index": "not_analyzed", "include_in_all": false}, | |
"indexable_content": {"type": "string", "index": "analyzed"} | |
} | |
} | |
} | |
}' | |
echo | |
curl -XPUT localhost:9200/test-idx/doc/1 -d '{ | |
"format": "test1", | |
"title": "blah", | |
"description": "blah", | |
"indexable_content": "keywords here" | |
}' | |
echo | |
curl -XPUT localhost:9200/test-idx/doc/2 -d '{ | |
"format": "test3", | |
"title": "blah", | |
"description": "blah", | |
"indexable_content": "keywords here" | |
}' | |
curl -XPOST localhost:9200/test-idx/_refresh | |
curl -XPOST "localhost:9200/test-idx/doc/_search?pretty=true&explain=true" -d '{ | |
"from": 0, | |
"query": { | |
"custom_filters_score": { | |
"filters": [ | |
{ | |
"boost": 1.5, | |
"filter": { | |
"term": { | |
"format": "test1" | |
} | |
} | |
}, | |
{ | |
"boost": 1.5, | |
"filter": { | |
"term": { | |
"format": "test2" | |
} | |
} | |
} | |
], | |
"query": { | |
"bool": { | |
"must": { | |
"query_string": { | |
"analyzer": "query_default", | |
"fields": [ | |
"title^5", | |
"description^2", | |
"indexable_content" | |
], | |
"query": "blah" | |
} | |
}, | |
"should": [] | |
} | |
} | |
} | |
}, | |
"size": 50 | |
}' | |
curl -XPOST "localhost:9200/test-idx/doc/_search?pretty=true" -d ' | |
{ | |
"from": 0, | |
"query": { | |
"bool": { | |
"must": [{ | |
"query_string": { | |
"analyzer": "query_default", | |
"fields": ["title^5", "description^2", "indexable_content"], | |
"query": "blah" | |
} | |
}, { | |
"term": { | |
"format": "test1" | |
} | |
}] | |
} | |
}, | |
"size": 50 | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment