| 8 | const isDevMode = process.env.NODE_ENV !== 'production' |
| 9 | |
| 10 | function getClient() { |
| 11 | if (!ELASTICSEARCH_URL) { |
| 12 | // If this was mistakenly not set, it will eventually fail |
| 13 | // when you use the Client. But `new Client({node: undefined})` |
| 14 | // won't throw. And the error you get when you actually do try |
| 15 | // to use that Client instance is cryptic compared to this |
| 16 | // plain and simple thrown error. |
| 17 | throw new Error(`$ELASTICSEARCH_URL is not set`) |
| 18 | } |
| 19 | return new Client({ |
| 20 | node: ELASTICSEARCH_URL, |
| 21 | // The default is 30,000ms but we noticed that the median time is about |
| 22 | // 100-150ms with some occasional searches taking multiple seconds. |
| 23 | // The default `maxRetries` is 5 which is a sensible number. |
| 24 | // If a query gets stuck, it's better to (relatively) quickly give up |
| 25 | // and retry. So if it takes longer than this time here, we're banking on |
| 26 | // that it was just bad luck and that it'll work if we simply try again. |
| 27 | // See internal issue #2318. |
| 28 | requestTimeout: 1000, |
| 29 | }) |
| 30 | } |
| 31 | |
| 32 | // The true work horse that actually performs the Elasticsearch query |
| 33 | export async function getSearchResults({ |