-
-
Save robfaraj/e251f1d3f0e17c2fa7ae 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
// Mapping | |
curl -XPUT 'http://localhost:9200/index/' -d '{ | |
"settings" : { | |
"number_of_shards" : 1, | |
"number_of_replicas" : 1 | |
}, | |
"mappings" : { | |
"type" : { | |
"_source" : {"enabled" : false}, | |
"_id" : {"store" : "yes"}, | |
"properties" : { | |
"title" : {"type" : "string", "store": "yes", "boost" : 5.0}, | |
"description" : {"type" : "string", "store": "no"}, | |
"item" : {"type" : "string", "store": "no", "boost" : 3.0 }, | |
"site" : {"type" : "string", "store": "no", "boost": 2.0, "index" : "not_analyzed"}, | |
"category" : {"type" : "integer", "store" : "no"}, | |
"subcategory" : {"type" : "integer", "store" : "no"}, | |
"status_id" : {"type" : "integer", "store" : "no"}, | |
"site_id" : {"type" : "integer", "store" : "yes"}, | |
"item_id" : {"type" : "integer", "store" : "yes"} | |
} | |
} | |
} | |
}' | |
// Put Some Sample Data | |
curl -s -XPUT http://localhost:9200/index/type/1/ -d ' | |
{ | |
"title":"foobar", | |
"site":"elasticsearch", | |
"description":"elasticsearch vs lucene vs solr vs sphinx vs mysql fulltext", | |
"item":"forum post", | |
"category":4, | |
"subcategory":5, | |
"status_id":1, | |
"site_id":7, | |
"item_id":9 | |
} | |
' | |
curl -s -XPUT http://localhost:9200/index/type/2/ -d ' | |
{ | |
"title":"foobared", | |
"site":"elasticsearch", | |
"description":"elasticsearch vs the machine", | |
"item":"forum post", | |
"category":3, | |
"subcategory":8, | |
"status_id":1, | |
"site_id":7, | |
"item_id":13 | |
} | |
' | |
// Searching for term + filter | |
curl -XPOST 'http://localhost:9200/index/type/_search?pretty=true&fields=_id,title' -d ' | |
{ | |
"query" : { | |
"query_string" : { | |
"query" : "foobar" | |
} | |
}, | |
"filter" : { | |
"term" : { | |
"status_id" : 1 | |
} | |
} | |
} | |
' | |
// Searching for filter across all records (with no term provided) | |
curl -XPOST 'http://localhost:9200/index/type/_search?pretty=true&fields=_id,item_id,title' -d ' | |
{ | |
"query" : { | |
"constant_score" : { | |
"filter": { | |
"term": { | |
"status_id": 1 | |
} | |
} | |
} | |
} | |
} | |
' | |
// Searching for filter across all records (w/no term) + with facets | |
curl -XPOST 'http://localhost:9200/index/type/_search?pretty=true&fields=_id,site_id,item_id,title' -d ' | |
{ | |
"query" : { | |
"constant_score" : { | |
"filter": { | |
"term": { | |
"status_id": 1 | |
} | |
}, | |
"facets" : { | |
"sites" : { | |
"terms" : { "field" : "site_id" } | |
} | |
} | |
} | |
} | |
} | |
' |
First one didn't work for me. I got a parse error. Changed it to this and it works...
curl -XPOST 'http://localhost:9200/index/type/_search?pretty=true&fields=_id,title' -d '
{
"query" : {
"query_string" : {
"query" : "foobar"
}
},
"filter" : {
"term" : {
"status_id" : 1
}
}
}
'
Constant score works nicely.
sorry - i typed it out manually, didn't test it :)
clint
…On Tue, 2011-03-15 at 08:29 -0700, robfaraj wrote:
First one didn't work for me. I got a parse error. Changed it to this and it works...
curl -XPOST 'http://localhost:9200/runtest/auction/_search?pretty=true&fields=_id,title,site_id,item_id,is_beginner' -d '
{
"query" : {
"query_string" : {
"query" : "foobar"
}
},
```
"filter" : {
"term" : {
"status_id" : 1
}
}
}
'
```
Constant score works nicely.
np. thanks for the help
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Searching for term + filter
// Use a filtered query:
// Searching for filter across all records (with no term provided)
// Wrap your filter in a constant_score query