All Projects → graphql-compose → Graphql Compose Elasticsearch

graphql-compose / Graphql Compose Elasticsearch

Licence: mit
Hide Elastic Search REST API behind GraphQL.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Graphql Compose Elasticsearch

Elastic Stack
Aprenda Elasticsearch, Logstash, Kibana e Beats do jeito mais fácil ⭐️
Stars: ✭ 135 (-72.89%)
Mutual labels:  elastic, elasticsearch
Elastix
A simple Elasticsearch REST client written in Elixir.
Stars: ✭ 231 (-53.61%)
Mutual labels:  elastic, elasticsearch
Elasticsearch Ruby
Ruby integrations for Elasticsearch
Stars: ✭ 1,848 (+271.08%)
Mutual labels:  elastic, elasticsearch
Elastic Docker
Example setups for Elasticsearch, Kibana, Logstash, and Beats with docker-compose
Stars: ✭ 118 (-76.31%)
Mutual labels:  elastic, elasticsearch
Helk
The Hunting ELK
Stars: ✭ 3,097 (+521.89%)
Mutual labels:  elastic, elasticsearch
Elastic
Elastic Stack (6.2.4) 을 활용한 Dashboard 만들기 Project
Stars: ✭ 121 (-75.7%)
Mutual labels:  elastic, elasticsearch
Elasticsearch Comrade
Elasticsearch admin panel built for ops and monitoring
Stars: ✭ 214 (-57.03%)
Mutual labels:  elastic, elasticsearch
Windows Installers
Windows installers for the Elastic stack
Stars: ✭ 101 (-79.72%)
Mutual labels:  elastic, elasticsearch
Elastichd
Elasticsearch 可视化DashBoard, 支持Es监控、实时搜索,Index template快捷替换修改,索引列表信息查看, SQL converts to DSL等
Stars: ✭ 2,993 (+501%)
Mutual labels:  elastic, elasticsearch
Spring Examples
SpringBoot Examples
Stars: ✭ 67 (-86.55%)
Mutual labels:  graphql, elasticsearch
Redelk
Red Team's SIEM - tool for Red Teams used for tracking and alarming about Blue Team activities as well as better usability in long term operations.
Stars: ✭ 1,692 (+239.76%)
Mutual labels:  elastic, elasticsearch
Pfelk
pfSense/OPNsense + ELK
Stars: ✭ 417 (-16.27%)
Mutual labels:  elastic, elasticsearch
Microservice Monitoring
Monitor your Spring Boot application with the Elastic Stack all around
Stars: ✭ 114 (-77.11%)
Mutual labels:  elastic, elasticsearch
Sigmaui
SIGMA UI is a free open-source application based on the Elastic stack and Sigma Converter (sigmac)
Stars: ✭ 123 (-75.3%)
Mutual labels:  elastic, elasticsearch
Elasticambari
Elastic Service for Ambari
Stars: ✭ 108 (-78.31%)
Mutual labels:  elastic, elasticsearch
Docker Elastic Stack
ELK Stack Dockerfile
Stars: ✭ 175 (-64.86%)
Mutual labels:  elastic, elasticsearch
Sentinl
Kibana Alert & Report App for Elasticsearch
Stars: ✭ 1,233 (+147.59%)
Mutual labels:  elastic, elasticsearch
Elastic Scout Driver Plus
Extension for Elastic Scout Driver
Stars: ✭ 90 (-81.93%)
Mutual labels:  elastic, elasticsearch
Serverless Appsync Plugin
serverless plugin for appsync
Stars: ✭ 804 (+61.45%)
Mutual labels:  graphql, elasticsearch
Elasticsearch Rails
Elasticsearch integrations for ActiveModel/Record and Ruby on Rails
Stars: ✭ 2,896 (+481.53%)
Mutual labels:  elastic, elasticsearch

graphql-compose-elasticsearch

npm trends Travis Commitizen friendly semantic-release

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.

import { GraphQLSchema, GraphQLObjectType } from 'graphql';
import elasticsearch from 'elasticsearch';
import { elasticApiFieldConfig } from 'graphql-compose-elasticsearch';

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      elastic50: elasticApiFieldConfig(
        // you may provide existed Elastic Client instance
        new elasticsearch.Client({
          host: 'http://localhost:9200',
          apiVersion: '5.0',
        })
      ),

      // or may provide just config
      elastic24: elasticApiFieldConfig({
        host: 'http://user:[email protected]:9200',
        apiVersion: '2.4',
      }),

      elastic17: elasticApiFieldConfig({
        host: 'http://user:[email protected]:9200',
        apiVersion: '1.7',
      }),
    },
  }),
});

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 search method. According to GraphQL adaptation and its projection bunch of params setup automatically due your graphql query (eg _source, explain, version, trackScores), other rare fine tuning params moved to opts input field.
  • searchConnection - elastic search method 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 before argument will not work.
  • searchPagination - elastic search method that has page and perPage arguments
  • findById - get elastic record by id
  • updateById - update elastic record by id
  • feel free to add your resolver or ask for a new one
import { GraphQLSchema, GraphQLObjectType } from 'graphql';
import elasticsearch from 'elasticsearch';
import { composeWithElastic } from 'graphql-compose-elasticsearch';

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 = composeWithElastic({
  graphqlTypeName: 'UserES',
  elasticIndex: 'user',
  elasticType: 'user',
  elasticMapping: mapping,
  elasticClient: new elasticsearch.Client({
    host: 'http://localhost:9200',
    apiVersion: '5.0',
    log: 'trace',
  }),
  // elastic mapping does not contain information about is fields are arrays or not
  // so provide this information explicitly for obtaining correct types in GraphQL
  pluralFields: ['skills', 'languages'],
});

const Schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      user: UserTC.getResolver('search').getFieldConfig(),
      userPagination: UserTC.getResolver('searchPagination').getFieldConfig(),
      userConnection: UserTC.getResolver('searchConnection').getFieldConfig(),
    },
  }),
});

Full code example

Installation

yarn add graphql graphql-compose elasticsearch graphql-compose-elasticsearch
// or
npm install graphql graphql-compose elasticsearch graphql-compose-elasticsearch --save

Modules graphql, graphql-compose, elasticsearch are in peerDependencies, so should be installed explicitly in your app.

Screenshots

API proxy: Raw search method

screen shot 2017-03-07 at 22 26 17

API proxy: Getting several raw elastic metric in one request

screen shot 2017-03-07 at 22 34 01

Mapping: Relay Cursor Connection

screen shot 2017-03-22 at 19 34 09

Mapping: Generated GraphQL Types and Documentation

screen shot 2017-03-22 at 19 33 24

FAQ

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):

ActivitiesEsTC.addResolver({
  name: 'addTag',
  kind: 'mutation',
  type: 'JSON',
  args: {
    id: 'String!',
    tag: 'String!',
  },
  resolve: ({ args }) => {
    return elasticClient.update({
      index: elasticIndex,
      type: elasticType,
      id: args.id,
      body: {
        script: {
          inline: 'ctx._source.tags.add(params.tag)',
          params: { tag: args.tag },
        },
      },
    });
  },
});

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].