Skip to content

Commit

Permalink
connect to ES 7.11 (github#30462)
Browse files Browse the repository at this point in the history
Co-authored-by: Rachael Sewell <rachmari@github.com>
  • Loading branch information
peterbe and rachmari authored Sep 6, 2022
1 parent 63599cf commit 54991f7
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 491 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
if: ${{ matrix.test-group == 'content' }}
uses: getong/elasticsearch-action@95b501ab0c83dee0aac7c39b7cea3723bef14954
with:
elasticsearch version: '7.17.5'
elasticsearch version: '7.11.1'
host port: 9200
container port: 9200
host node port: 9300
Expand Down
38 changes: 21 additions & 17 deletions middleware/api/es-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,24 @@ export async function getSearchResults({
const highlight = getHighlightConfiguration(query)

const searchQuery = {
index: indexName,
highlight,
from,
size,
// Since we know exactly which fields from the source we're going
// need we can specify that here. It's an inclusion list.
// We can save precious network by not having to transmit fields
// stored in Elasticsearch to here if it's not going to be needed
// anyway.
_source_includes: [
'title',
'url',
'breadcrumbs',
// 'headings'
'popularity',
],

// COMMENTED out because of ES 7.11.
// Once we're on ES >7.11 we can add this option in.
// // Since we know exactly which fields from the source we're going
// // need we can specify that here. It's an inclusion list.
// // We can save precious network by not having to transmit fields
// // stored in Elasticsearch to here if it's not going to be needed
// // anyway.
// _source_includes: [
// 'title',
// 'url',
// 'breadcrumbs',
// // 'headings'
// 'popularity',
// ],
}

if (includeTopics) {
Expand Down Expand Up @@ -107,15 +109,17 @@ export async function getSearchResults({
throw new Error(`Unrecognized sort enum '${sort}'`)
}

const result = await client.search(searchQuery)
const result = await client.search({ index: indexName, body: searchQuery })

const hits = getHits(result.hits.hits, { indexName, debug, includeTopics })
// const hitsAll = result.hits // ES >7.11
const hitsAll = result.body // ES <=7.11
const hits = getHits(hitsAll.hits.hits, { indexName, debug, includeTopics })
const t1 = new Date()

const meta = {
found: result.hits.total,
found: hitsAll.hits.total,
took: {
query_msec: result.took,
query_msec: hitsAll.took,
total_msec: t1.getTime() - t0.getTime(),
},
page,
Expand Down
Loading

0 comments on commit 54991f7

Please sign in to comment.