This module expose Elastic Search REST API via GraphQL.
Elastic Search REST API proxy
Supported all elastic versions that support official elasticsearch-js client. Internally it parses its source code annotations and generates all available methods with params and descriptions to GraphQL Field Config Map. You may put this config map to any GraphQL Schema.
;;;const schema =query:name: 'Query'fields:elastic50:// or may provide just configelastic24:elastic17:;
Full code example
Live demo of Introspection of Elasticsearch API via Graphiql
ObjectTypeComposer from Elastic mapping
In other side this module is a plugin for graphql-compose, which derives GraphQLType from your elastic mapping generates tons of types, provides all available methods in QueryDSL, Aggregations, Sorting with field autocompletion according to types in your mapping (like Dev Tools Console in Kibana).
Generated ObjectTypeComposer model has several awesome resolvers:
search- greatly simplified elastic
searchmethod. According to GraphQL adaptation and its projection bunch of params setup automatically due your graphql query (eg
trackScores), other rare fine tuning params moved to
searchmethod that implements Relay Cursor Connection spec for infinite lists. Internally it uses cheap search_after API. One downside, Elastic does not support backward scrolling, so
beforeargument will not work.
searchmethod that has
findById- get elastic record by id
updateById- update elastic record by id
- feel free to add your resolver or ask for a new one
;;;const mapping =properties:name:type: 'text'fields:keyword:type: 'keyword'gender:type: 'keyword'skills:type: 'text'languages:type: 'keyword'location:properties:name:type: 'text'point:type: 'geo_point'createdAt:type: 'date';const UserTC =;const Schema =query:name: 'Query'fields:user: UserTCuserPagination: UserTCuserConnection: UserTC;
Full code example
yarn add graphql graphql-compose elasticsearch graphql-compose-elasticsearch// ornpm install graphql graphql-compose elasticsearch graphql-compose-elasticsearch --save
elasticsearch are in
peerDependencies, so should be installed explicitly in your app.
API proxy: Raw search method
API proxy: Getting several raw elastic metric in one request
Mapping: Relay Cursor Connection
Mapping: Generated GraphQL Types and Documentation
Creating custom Resolvers
If you need create something special, you may create a custom Resolver. For example, if you need to add a new tag for existing record, do it in the following manner (see full test-case):