https://github.com/idiocc/elastic
A Library To Manage Operations On ElasticSearch.
https://github.com/idiocc/elastic
Last synced: 8 months ago
JSON representation
A Library To Manage Operations On ElasticSearch.
- Host: GitHub
- URL: https://github.com/idiocc/elastic
- Owner: idiocc
- License: mit
- Created: 2018-11-14T19:07:44.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-15T16:37:43.000Z (over 7 years ago)
- Last Synced: 2025-03-17T03:03:36.359Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://idio.cc
- Size: 28.3 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @idio/elastic
[](https://npmjs.org/package/@idio/elastic)
`@idio/elastic` Is A Library To Manage Operations On ElasticSearch.
```sh
yarn add -E @idio/elastic
```
## Table Of Contents
- [Table Of Contents](#table-of-contents)
- [API](#api)
- [`async search(client: Client, searchParams: SearchParams, queryParams?: Object): Hits[]`](#async-searchclient-clientsearchparams-searchparamsqueryparams-object-hits)
* [`Hit`](#type-hit)
- [Copyright](#copyright)
## API
The package is available by importing its components functions:
```js
import { search } from '@idio/elastic'
```
## `async search(`
`client: Client,`
`searchParams: SearchParams,`
`queryParams?: Object,`
`): Hits[]`
The wrapper around search to make a query based on a data object. Returns an empty array no no hits are found.
`import('elasticsearch').Client` __`Client`__
`import('elasticsearch').SearchParams` __`SearchParams`__
__`Hit`__
| Name | Type | Description |
| --------------- | ------------- | ---------------------------------------- |
| ___id*__ | _string_ | `DQn4JC6q5zZQsgv5KNhiWlgd` |
| ___index*__ | _string_ | `idio-example` |
| ___score*__ | _number_ | `1` |
| ___source*__ | _*_ | `Object {name: "example", user: "idio"}` |
| ___type*__ | _string_ | `doc` |
| _version | _number_ | |
| _explanation | _Explanation_ | |
| fields | _*_ | |
| highlight | _*_ | |
| inner_hits | _*_ | |
| matched_queries | _string[]_ | |
| sort | _string[]_ | |
```js
const INDEX = 'idio-example'
;(async () => {
// 1. Create a record in ElasticSearch for the example.
const { id, client } = await getClient()
const res = await search(client, {
index: INDEX,
type: 'doc',
}, { _id: id })
console.log(res)
})()
```
```
[ { _index: 'idio-example',
_type: 'doc',
_id: '7Tn79YCXy9lKoxQi7l9k0SHq',
_score: 1,
_source:
{ name: 'example',
user: 'idio',
date: '2018-11-15T15:57:52.031Z' } } ]
```
## Copyright
(c) [Idio][1] 2018
[1]: https://idio.cc