Skip to content

Instantly share code, notes, and snippets.

@robfaraj
Created March 16, 2011 19:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robfaraj/f8a124e09faf61cff35b to your computer and use it in GitHub Desktop.
Save robfaraj/f8a124e09faf61cff35b to your computer and use it in GitHub Desktop.
// No Term Provided
//
// SELECT id FROM type
// WHERE site_id IN (1,7) AND status_id=2 AND branch_id=1651
// ORDER BY branch_id DESC
//
curl -XPOST 'http://localhost:9200/index/type/_search?pretty=true&fields=_id' -d '
{
"query" : {
"constant_score" : {
"filter" : {
"and" : [
{
"query" : {
"field": {
"site_id" : "1 OR 7"
}
}
},
{
"term": {
"status_id": 2
}
},
{
"term": {
"branch_id": 1651
}
}
]
}
}
},
"sort" : [
{ "branch_id" : {"reverse" : false} },
"_score"
],
"facets" : {
"sites" : {
"terms" : { "field" : "type_id" }
},
"status" : {
"terms" : { "field" : "status_id" }
}
}
}
'
// Term Provided
//
// SELECT id FROM type
// WHERE _all LIKE (%foobar%) AND site_id IN (1,7) AND status_id=2 AND branch_id=1651
// ORDER BY branch_id DESC
//
curl -XPOST 'http://localhost:9200/index/type/_search?pretty=true&fields=_id' -d '
{
"query" : {
"filtered" : {
"query" : {
"query_string" : {
"query" : "foobar"
}
},
"filter" : {
"and" : [
{
"query" : {
"field": {
"site_id" : "1 OR 7"
}
}
},
{
"term": {
"status_id": 2
}
},
{
"term": {
"branch_id": 1651
}
}
]
}
}
},
"sort" : [
{ "branch_id" : {"reverse" : true} },
"_score"
],
"facets" : {
"sites" : {
"terms" : { "field" : "type_id" }
},
"status" : {
"terms" : { "field" : "status_id" }
}
}
}
'
@clintongormley
Copy link

Right, I didn't notice that. The one good thing about using _source instead of storing each field separately, is that it makes it easy to reindex your data when you decide to change your mapping, or you upgrade and something core has changed which requires reindexing.

_all maps to all 8 fields - its includes all fields, exceptany which have include_in_all set to false. The value of store has no impact on inclusion in _all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment