add production search config
This commit is contained in:
parent
d22991bc3b
commit
af2c990a51
@ -277,8 +277,10 @@ export default {
|
|||||||
},
|
},
|
||||||
search: async (parent, { q: query, cursor }, { models, search }) => {
|
search: async (parent, { q: query, cursor }, { models, search }) => {
|
||||||
const decodedCursor = decodeCursor(cursor)
|
const decodedCursor = decodeCursor(cursor)
|
||||||
|
let sitems
|
||||||
|
|
||||||
const sitems = await search.search({
|
try {
|
||||||
|
sitems = await search.search({
|
||||||
index: 'item',
|
index: 'item',
|
||||||
size: LIMIT,
|
size: LIMIT,
|
||||||
from: decodedCursor.offset,
|
from: decodedCursor.offset,
|
||||||
@ -326,6 +328,13 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
return {
|
||||||
|
cursor: null,
|
||||||
|
items: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const items = sitems.body.hits.hits.map(e => e._source)
|
const items = sitems.body.hits.hits.map(e => e._source)
|
||||||
return {
|
return {
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
import es from '@opensearch-project/opensearch'
|
const os = require('@opensearch-project/opensearch')
|
||||||
|
|
||||||
global.es ||= new es.Client({ node: 'http://localhost:9200' })
|
global.os = global.os || new os.Client(
|
||||||
|
process.env.NODE_ENV === 'production'
|
||||||
|
? {
|
||||||
|
node: process.env.OPENSEARCH_URL,
|
||||||
|
auth: {
|
||||||
|
username: process.env.OPENSEARCH_USERNAME,
|
||||||
|
password: process.env.OPENSEARCH_PASSWORD
|
||||||
|
}
|
||||||
|
}
|
||||||
|
: { node: 'http://localhost:9200' })
|
||||||
|
|
||||||
export default global.es
|
module.exports = global.os
|
||||||
|
38
package-lock.json
generated
38
package-lock.json
generated
@ -9,7 +9,6 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apollo/client": "^3.4.15",
|
"@apollo/client": "^3.4.15",
|
||||||
"@elastic/elasticsearch": "^7.16.0",
|
|
||||||
"@opensearch-project/opensearch": "^1.0.2",
|
"@opensearch-project/opensearch": "^1.0.2",
|
||||||
"@prisma/client": "^2.25.0",
|
"@prisma/client": "^2.25.0",
|
||||||
"apollo-server-micro": "^2.21.2",
|
"apollo-server-micro": "^2.21.2",
|
||||||
@ -352,25 +351,6 @@
|
|||||||
"node": ">=6.9.0"
|
"node": ">=6.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@elastic/elasticsearch": {
|
|
||||||
"version": "7.16.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@elastic/elasticsearch/-/elasticsearch-7.16.0.tgz",
|
|
||||||
"integrity": "sha512-lMY2MFZZFG3om7QNHninxZZOXYx3NdIUwEISZxqaI9dXPoL3DNhU31keqjvx1gN6T74lGXAzrRNP4ag8CJ/VXw==",
|
|
||||||
"dependencies": {
|
|
||||||
"debug": "^4.3.1",
|
|
||||||
"hpagent": "^0.1.1",
|
|
||||||
"ms": "^2.1.3",
|
|
||||||
"secure-json-parse": "^2.4.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=12"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@elastic/elasticsearch/node_modules/ms": {
|
|
||||||
"version": "2.1.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
|
||||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
|
|
||||||
},
|
|
||||||
"node_modules/@eslint/eslintrc": {
|
"node_modules/@eslint/eslintrc": {
|
||||||
"version": "0.4.3",
|
"version": "0.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.3.tgz",
|
||||||
@ -12233,24 +12213,6 @@
|
|||||||
"to-fast-properties": "^2.0.0"
|
"to-fast-properties": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@elastic/elasticsearch": {
|
|
||||||
"version": "7.16.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@elastic/elasticsearch/-/elasticsearch-7.16.0.tgz",
|
|
||||||
"integrity": "sha512-lMY2MFZZFG3om7QNHninxZZOXYx3NdIUwEISZxqaI9dXPoL3DNhU31keqjvx1gN6T74lGXAzrRNP4ag8CJ/VXw==",
|
|
||||||
"requires": {
|
|
||||||
"debug": "^4.3.1",
|
|
||||||
"hpagent": "^0.1.1",
|
|
||||||
"ms": "^2.1.3",
|
|
||||||
"secure-json-parse": "^2.4.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"ms": {
|
|
||||||
"version": "2.1.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
|
||||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"@eslint/eslintrc": {
|
"@eslint/eslintrc": {
|
||||||
"version": "0.4.3",
|
"version": "0.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.3.tgz",
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apollo/client": "^3.4.15",
|
"@apollo/client": "^3.4.15",
|
||||||
"@elastic/elasticsearch": "^7.16.0",
|
|
||||||
"@opensearch-project/opensearch": "^1.0.2",
|
"@opensearch-project/opensearch": "^1.0.2",
|
||||||
"@prisma/client": "^2.25.0",
|
"@prisma/client": "^2.25.0",
|
||||||
"apollo-server-micro": "^2.21.2",
|
"apollo-server-micro": "^2.21.2",
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
const { gql } = require('apollo-server-micro')
|
const { gql } = require('apollo-server-micro')
|
||||||
const es = require('@opensearch-project/opensearch')
|
const search = require('../api/search')
|
||||||
|
|
||||||
const search = new es.Client({ node: 'http://localhost:9200' })
|
|
||||||
|
|
||||||
const ITEM_SEARCH_FIELDS = gql`
|
const ITEM_SEARCH_FIELDS = gql`
|
||||||
fragment ItemSearchFields on Item {
|
fragment ItemSearchFields on Item {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user