Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save abhiesa-tolexo/38dcc9419ecd0bc8f646 to your computer and use it in GitHub Desktop.
Save abhiesa-tolexo/38dcc9419ecd0bc8f646 to your computer and use it in GitHub Desktop.
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