-
-
Save robfaraj/f8a124e09faf61cff35b 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
// 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" } | |
} | |
} | |
} | |
' |
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
I'm not storing
_source
because I have set"_source" : {"enabled" : false}
in my mapping. I'm only retrieving certain fields from elastic search. I've marked those with"store": "yes"
in my mapping. The rest are there for searching or filtering.In my example above does
_all
map to all 8 fields or just the 4 fields of string type?