Skip to content

Instantly share code, notes, and snippets.

@emmanuelbernard
Last active April 3, 2017 22:12
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 emmanuelbernard/5760676 to your computer and use it in GitHub Desktop.
Save emmanuelbernard/5760676 to your computer and use it in GitHub Desktop.
/* vim: set softtabstop=4 shiftwidth=4 expandtab
* vim: set filetype=js
*/
// Keyword query
{
"class": "Show",
"firstResult": 0,
"maxResults": 20,
"query": {
"keyword": {
"fields": [
{
"name": "event.name",
"boost": 1,
"ignoreAnalyzer": true,
"ignoreFieldBridge": true
},
{
"name": "event.description"
}
],
"matching": "Decade"
},
"boost": 2,
"constantScore": true,
"filter": "TODO?"
}
}
// fuzzy
{
"class": "Show",
"overrides": [
{ "field": "event.name", "analyzerName": "ngram" }
],
"query": {
"keyword": {
"fuzzy": {
"threshold": 0.8,
"prefixLength": 1
},
/* can we support "fields": [ "event.description", "event.name" ], */
"fields": [
{
"name": "event.description"
}
],
"matching": "Decade"
}
}
}
// wildcard
{
"class": "Show",
"query": {
"keyword": {
"wildcard": true,
// should it be "field": "event.description",
"field": {
"name": "event.description",
"boost": 3
},
"matching": "Deca*"
}
}
}
// Boolean query
{
"class": "Show",
"query" : {
"bool": [
{
"type": "should",
"query" : {
"keyword": {
"fuzzy": {
"threshold": 0.8,
"prefixLength": 1
},
"field": "event.name",
"matching": "Decade"
}
}
},
{
"type": "must",
"negate": true, //or should it be "type": "must_not",
"query" : { ... }
}
]
}
}
// all (except)
{
"class": "Show",
"query" : {
"all": {
"except": [
{ "keyword": {"field": "event.name", "matching": "Decade"} }
]
}
}
}
{
"class": "Show",
"query": {
"all": {} //meh
}
}
// Range queries
{
"class": "Show",
"query" : {
"range": {
"field": "ticketPrices.min",
"below": "50",
"excludeLimit": true
}
}
}
{
"class": "Show",
"query" : {
"range": {
"field": "ticketPrices.min",
"from": "50",
"to": "100"
// TODO how to deal with "excludeLimit": true
}
}
}
//Phrase
{
"class": "Show",
"query": {
"phrase": {
"slop": 3,
"fields": ["event.description", "venue.description"],
"sentence": "colder and whitening"
}
}
}
//Spatial
{
"class": "Show",
"query": {
"spatial": {
"coordinates": "coordinates_field", // "defaultCoordinates": true ?
"within": { "distance": 50, "unit": "km" },
"of": {"latitude": 23.2323, "longitude": 12.111 }
}
}
}
//Faceting
{
"class": "Show",
"query": {
"keyword": {
"fields": [
{
"name": "event.name",
"boost": 1,
"ignoreAnalyzer": true,
"ignoreFieldBridge": true
},
{
"name": "event.description"
}
],
"matching": "Decade"
},
"boost": 2,
"constantScore": true,
"filter": "TODO?"
},
"faceting": [
{
"name": "category",
"field": "event.category",
"discrete": {},
"orderedBy": "FIELD_VALUE",
"includeZeroCount": true,
"maxFacetCount": 20
},
{
"name": "minprice",
"field": "ticketPrices.min",
"range": [
{ "below": 50, "excludeLimit": true },
{ "from": 50, "to": 100, "excludeToLimit": true }, //TODO excludeLimit???
{ "from": 100, "to": 200, "excludeToLimit": true }, //TODO excludeLimit???
{ "above": 200 }
],
"includeZeroCount": true,
"orderedBy": "RANGE_DEFINITION_ORDER"
}
]
}
//Faceting with selection
{
"class": "Show",
"query": {
"keyword": {
"fields": [
{
"name": "event.name",
"boost": 1,
"ignoreAnalyzer": true,
"ignoreFieldBridge": true
},
{
"name": "event.description"
}
],
"matching": "Decade"
},
"boost": 2,
"constantScore": true,
"filter": "TODO?"
},
"faceting": [
{
"name": "category",
"field": "event.category",
"discrete": { "selectedIds": [1, 3] }, //or "selectedValues": ["concert"]
"orderedBy": "FIELD_VALUE",
"includeZeroCount": true,
"maxFacetCount": 20
},
{
"name": "minprice",
"field": "ticketPrices.min",
"range": [
{ "below": 50, "excludeLimit": true },
{ "from": 50, "to": 100, "excludeToLimit": true, "selected": true }, //TODO excludeLimit???
{ "from": 100, "to": 200, "excludeToLimit": true }, //TODO excludeLimit???
{ "above": 200 }
],
"includeZeroCount": true,
"orderedBy": "RANGE_DEFINITION_ORDER"
}
]
}
@Sanne
Copy link

Sanne commented Jun 11, 2013

Great examples, all very readable.

The only one which is puzzling me a bit is the "discrete" example (you have two); I don't think either is very self-explanatory.

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