CARVIEW |
Select Language
HTTP/2 200
date: Wed, 23 Jul 2025 14:28:59 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"a3ceb6f09d067a08303ab62613030b35"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=ao%2FsTOn9Ox6J1%2B3ZX4C5a9udPSQF4GtU3%2FlscqB0yD7W%2B61rbQlr3fA5O9u5S306L5PN5%2Bb6X5dpA64c%2FROFI0kiTcVg8wO3poBz1Hl28X5FQHeWh8twZ6uom5Zi%2Fg06pApmrXhWGclqLO%2FPTQXdTfWuzWvZacozWN9AoxfKAT%2FmZpj5vHZrUwoNxq62vyKOYgEYysuSO2nqmUlEkFm%2Bf%2F%2FRPMjaBN35bUdpgopuwHVijCI5lH9NQUkmCy%2Bnd2ZIxaSgtH2%2BpWbBEGBnVUMxRw%3D%3D--fSpb%2B1mCIcwWGAlZ--TGeE82LpRAf5lCxMvaV%2FXw%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1161986827.1753280939; Path=/; Domain=github.com; Expires=Thu, 23 Jul 2026 14:28:59 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Thu, 23 Jul 2026 14:28:59 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: 9B3E:2FAFD7:D3019D:F9C6BE:6880F1AB
Some example queries using elastic.js · GitHub
Show Gist options
Save egaumer/4519444 to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
Last active
June 26, 2019 20:21
-
Star
24
(24)
You must be signed in to star a gist -
Fork
4
(4)
You must be signed in to fork a gist
-
Save egaumer/4519444 to your computer and use it in GitHub Desktop.
Some example queries using elastic.js
This file contains hidden or 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
# simple match all query with term facet | |
ejs.Request() | |
.indices("myindex") | |
.types("mytype") | |
.query(ejs.MatchAllQuery()) | |
.facet( | |
ejs.TermsFacet('url') | |
.field('url') | |
.size(20)) | |
# filtered query with GeoDistance filter | |
ejs.Request() | |
.indices("myindex") | |
.types("mytype") | |
.query( | |
ejs.FilteredQuery( | |
ejs.MatchAllQuery(), | |
ejs.GeoDistanceFilter("location") | |
.distance(10) | |
.point(ejs.GeoPoint([40.53555, -75.57655])))) | |
# an advanced dismax query used to return "featured results" | |
ejs.Request() | |
.indices("myindex") | |
.types("mytype") | |
.query( | |
ejs.BoolQuery() | |
.should( | |
ejs.FilteredQuery( | |
ejs.DisMaxQuery() | |
.queries(ejs.MatchQuery('title', 'keyword')) | |
.queries(ejs.MatchQuery('content', 'keyword')) | |
.queries(ejs.MatchQuery('title', 'keyword') | |
.boost(2) | |
.type('phrase') | |
.slop(5)) | |
.queries(ejs.MatchQuery('content', 'keyword') | |
.boost(2) | |
.type('phrase') | |
.slop(20)) | |
.tieBreaker(0.1), | |
ejs.NotFilter(ejs.TypeFilter('featured')))) | |
.should( | |
ejs.ConstantScoreQuery() | |
.query(ejs.MatchQuery('keywords', 'keyword')) | |
.boost(1000000))) | |
# basic mult-select faceting | |
var colors = ejs.TermsFilter('color', ['green', 'red']), | |
shapes = ejs.TermsFilter('shape', ['square']), | |
tags = ejs.TermsFilter('tags', ['tag2', 'tag4']), | |
keywords = ejs.TermsFilter('keywords', ['keyword2', 'keyword3']) | |
ejs.Request() | |
.query(ejs.MatchAllQuery()) | |
.filter(ejs.AndFilter([colors, shapes, tags, keywords])) | |
.facet( | |
ejs.TermsFacet('shapeFacet') | |
.field('shape') | |
.allTerms(true) | |
.facetFilter(ejs.AndFilter([colors, tags, keywords]))) | |
.facet( | |
ejs.TermsFacet('colorFacet') | |
.field('color') | |
.allTerms(true) | |
.facetFilter(ejs.AndFilter([shapes, tags, keywords]))) | |
.facet( | |
ejs.TermsFacet('tagsFacet') | |
.field('tags') | |
.allTerms(true) | |
.facetFilter(ejs.AndFilter([colors, shapes, keywords]))) | |
.facet( | |
ejs.TermsFacet('keywordsFacet') | |
.field('keywords') | |
.allTerms(true) | |
.facetFilter(ejs.AndFilter([shapes, tags, keywords]))) | |
Aggregations with nested and using filters with and filter....... :)
ejs.Request().agg(
ejs.FilterAggregation('MainFilter').filter
(
ejs.AndFilter
([
ejs.TermFilter('Hospital','XXX'),
ejs.RangeFilter('log_date').from('2014-05-05 00:00:00.000').to('2014-05-11 00:00:00.000')
])
)
.agg
(
ejs.DateHistogramAggregation('DailyTime').field('log_date').interval('1d').format('E')
.agg
(
ejs.DateHistogramAggregation('HourlyTime').field('log_date').interval('1h')
.agg
(
ejs.SumAggregation('hourlyEDuration').field('EDuration')
)
.agg
(
ejs.CardinalityAggregation('hourlyECount').field('RowKEy')
)
)
.agg
(
ejs.SumAggregation('dailyEDuration').field('EDuration')
)
.agg
(
ejs.CardinalityAggregation('dailyECount').field('RowKEy')
)
)
)
These examples are extremely helpful, so I'm contributing back a query that I just wrote.
ejs.Request()
.size(0)
.query(ejs.FilteredQuery(
ejs.MatchAllQuery(),
ejs.BoolFilter()
.must(ejs.PrefixFilter('host', 'els-host'))
.must(ejs.RangeFilter('CollectionDateTime').gte('now-5m'))
))
.agg(ejs.TermsAggregation('host').field('host')
.agg(ejs.StatsAggregation('all').field('jvm.mem.heap_used_percent'))
.agg(ejs.FilterAggregation('highwater')
.filter(ejs.RangeFilter('jvm.mem.heap_used_percent').gt(68))
.agg(ejs.ValueCountAggregation('count').field('jvm.mem.heap_used_percent'))
)
)
;
This query expands to the following JSON.
{
"size": 0,
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {
"bool": {
"must": [
{"prefix": {"host": "els-host"}},
{"range": {"CollectionDateTime": {"gte": "now-5m"}}}
]
}
}
}
},
"aggs": {
"host": {
"terms": {"field": "host"},
"aggs": {
"all": {"stats": {"field": "jvm.mem.heap_used_percent"}},
"highwater": {
"filter": {"range": {"jvm.mem.heap_used_percent": {"gt": 68}}
},
"aggs": {
"count": {
"value_count": {"field": "jvm.mem.heap_used_percent"}
}
}
}
}
}
}
}
Good job.
Thank you. I found these useful. Some of the queries I wrote(and combined painstakingly):
var searchQuery = ejs.BoolQuery()
.should(ejs.MultiMatchQuery(["qualifiedProductName^1.5", "qualifiedProductName.shingles"])
.query('{{query_string}}')
.type('most_fields')
.minimumShouldMatch('65%')
.cutoffFrequency(0.01)
.lenient(true)
.boost(12))
.should(ejs.NestedQuery('dcs')
.query(ejs.MultiMatchQuery(["dcs.departmentName^8", "dcs.categoryName^2", "dcs.subCategoryName"])
.query('{{query_string}}')
.type('best_fields')
.minimumShouldMatch('75%')
.tieBreaker(0.3)
.fuzziness('AUTO')
.lenient(true)
.boost(4)))
.should(ejs.MultiMatchQuery([
"collectionsFeature^1.5", "colourFeature^1.5",
"materialFeature^1.5", "genderFeature^2",
"sizeDiapersFeature^2", "longDesc"
])
.query('{{query_string}}')
.type('most_fields')
.minimumShouldMatch('20%')
.fuzziness('AUTO')
.lenient(true)
.boost(2))
.should(ejs.MatchQuery('productId', '{{query_string}}'));
var topHitsAggs = ejs.Request()
.agg(ejs.TermsAggregation('variantGrouping')
.field('virtualGroupingId')
.size(0)
.order('max_score', 'desc')
.agg(ejs.TopHitsAggregation('variants').size(60))
.agg(ejs.MaxAggregation('max_score').lang('expression').script('_score')));
var facetAggs = JSON.parse(JSON.stringify(ejs.Request()
.agg(ejs.NestedAggregation('dcs')
.path('dcs')
.agg(ejs.TermsAggregation('departmentName')
.size(0)
.field('dcs.departmentName.raw')
.agg(ejs.TermsAggregation('categoryName')
.size(0)
.field('dcs.categoryName.raw')
.agg(ejs.TermsAggregation('subCategoryName')
.size(0)
.field('dcs.subCategoryName.raw')))))
.agg(ejs.HistogramAggregation('price')
.field('defaultPrice')
.minDocCount(1)
.interval(500))
.agg(ejs.StatsAggregation('priceStats')
.field('defaultPrice'))
.agg(ejs.HistogramAggregation('discountPercent')
.field('discountPercent')
.interval(10))
.agg(ejs.TermsAggregation('brand')
.field('brandName')
.size(0)
.order('_term', 'asc'))
.agg(ejs.TermsAggregation('colour')
.field('colourFeature.raw')
.size(0)
.order('_term', 'asc')).toJSON()));
# some code
return ejs.Request()
.agg(ejs.NestedAggregation('dynamicAggs')
.path('aggregationFields')
.agg(ejs.FilterAggregation('dynamicfilter')
.filter(termFilter)
.agg(ejs.TermsAggregation('key')
.field('aggregationFields.key')
.size(0)
.agg(ejs.TermsAggregation('value')
.field('aggregationFields.value')
.size(0)))));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.
please also write a sample to query inner/nested object fields