7.0.0 • Published 2 days ago

@nodefony/elastic-bundle v7.0.0

Weekly downloads
1
License
-
Repository
-
Last release
2 days ago

Welcome to elastic-bundle

Register and Configure elastic Bundle

For a Register elastic-bundle add elastic: true in config framework

./config/config.js

module.exports = {
  system: {
    /**
    * BUNDLES CORE
    */
    elastic: true
  }
}

Override elastic-bundle configuration your bundle

./app/config/config.js

/**
 * OVERRIDE ELASTIC BUNDLE SETTINGS
 *   elasticsearch
 *
 *	 options  :  https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-configuration.html
 *
 */
"elastic-bundle": {
  elasticsearch: {
    globalOptions: {
      ssl: {
        //key : path.resolve("config","certificates","server","privkey.pem"),
        //cert : path.resolve("config","certificates","server","cert.pem"),
        //ca : path.resolve("config","certificates","ca","nodefony-root-ca.crt.pem")
      }
    },
    connections: {
      main: {
        name: "main",
        nodes: ["http://localhost:9200"],
        log: {
          request: false,
          response: false,
          sniff: true,
          resurrect: true
        },
        maxRetries:10,
        sniffInterval: 5000,
        pingTimeout: 5000,
        requestTimeout:5000
      }
    }
  }
},

Example to use :

./controller/elasticController.js

/**
 *    @Route ("/test/elastic")
 */
module.exports = class elasticController extends nodefony.controller {

  constructor(container, context) {
    super(container, context);
    this.elastic = this.get("elastic");
    this.setJsonContext();
  }

  async getClient() {
    let conn = await this.elastic.getConnection("main");
    return conn.client;
  }

  async createIndex(index, id) {
    if (!index) {
      index = "nodefony";
    }
    const client = await this.getClient();
    const {
      body
    } = await client.indices.exists({
      index: index
    });
    let res = null;
    if (!body) {
      res = await client.index({
        index: index,
        id: id,
        body: {
          version: this.kernel.version,
          package: this.kernel.package
        }
      });
    } else {
      this.log(`Index : ${index} Already exist !!! `);
    }
    return res;
  }

  async ping() {
    return await this.client.ping();
  }

  /**
   *    @Method ({"GET"})
   *    @Route ("/index/{id}" , name="test-elastic-search", defaults={"id" = 1},requirements={"id" = "\d+")
   *
   */
  async indexAction(id) {
    const client = await this.getClient();
    await this.createIndex("nodefony", "id");
    let get = null ;
    try{
      get = await client.get({
        index: 'nodefony',
        id: id
      });
      return this.renderJson(get)
        .catch((e) => {
          throw e;
        });
    }catch(e){
      if ( e && e.meta && e.meta.statusCode ){
        return this.renderJson(e, e.meta.statusCode )
          .catch((e) => {
            throw e;
          });
      }
      return this.renderJson(e )
        .catch((e) => {
          throw e;
        });
    }
  }
};

Authors

  • Camensuli Christophe ccamensuli@gmail.com

License

7.0.0

2 days ago

7.0.0-beta.22

7 months ago

7.0.0-beta.21

7 months ago

7.0.0-beta.20

1 year ago

7.0.0-beta.19

1 year ago

7.0.0-beta.15

1 year ago

7.0.0-beta.16

1 year ago

7.0.0-beta.17

1 year ago

7.0.0-beta.18

1 year ago

7.0.0-beta.11

1 year ago

7.0.0-beta.12

1 year ago

7.0.0-beta.13

1 year ago

7.0.0-beta.14

1 year ago

7.0.0-beta.10

1 year ago

7.0.0-beta.9

1 year ago

7.0.0-beta.8

2 years ago

7.0.0-beta.6

2 years ago

7.0.0-beta.7

2 years ago

7.0.0-beta.4

2 years ago

7.0.0-beta.5

2 years ago

7.0.0-beta.2

2 years ago

7.0.0-beta.3

2 years ago

7.0.0-beta.0

2 years ago

7.0.0-beta.1

2 years ago

6.12.0

2 years ago

6.11.0

2 years ago

6.10.0

2 years ago

6.8.0

3 years ago

6.9.0

3 years ago

6.9.1

3 years ago

6.6.0

3 years ago

6.5.7

3 years ago

6.5.6

3 years ago

6.5.5

3 years ago

6.5.2

3 years ago

6.5.4

3 years ago

6.5.3

3 years ago

6.5.1

3 years ago

6.5.0

3 years ago

6.4.3

3 years ago

6.4.2

3 years ago

6.4.1

3 years ago

6.4.0

3 years ago

6.3.0

3 years ago

6.2.0

3 years ago

6.1.0

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

6.0.0-beta.16

4 years ago

6.0.0-beta.15

4 years ago

6.0.0-beta.14

4 years ago

6.0.0-beta.13

4 years ago

6.0.0-beta.12

4 years ago

6.0.0-beta.11

4 years ago

6.0.0-beta.10

4 years ago

6.0.0-beta.9

4 years ago

6.0.0-beta.8

4 years ago

6.0.0-beta.7

4 years ago

6.0.0-beta.6

4 years ago

6.0.0-beta.5

4 years ago

6.0.0-beta.4

4 years ago

6.0.0-beta.3

4 years ago

6.0.0-beta.2

4 years ago

6.0.0-beta.1

4 years ago

5.1.1

5 years ago

5.1.0

5 years ago

5.0.9

5 years ago

5.0.8

5 years ago

5.0.7

5 years ago

5.0.6

5 years ago

5.0.5

5 years ago

5.0.4

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.3.3

5 years ago

4.3.2

5 years ago

4.3.1

5 years ago

4.3.0

5 years ago

4.2.0-beta.2

5 years ago

4.2.0-beta.1

5 years ago

4.1.0-beta.4

5 years ago

4.1.0-beta.3

5 years ago

4.1.0-beta.2

5 years ago

4.1.0-beta.1

5 years ago

4.0.0-beta.22

5 years ago

4.0.0-beta.21

5 years ago

4.0.0-beta.20

5 years ago

4.0.0-beta.19

5 years ago

4.0.0-beta.18

5 years ago

4.0.0-beta.17

5 years ago

4.0.0-beta.16

5 years ago

4.0.0-beta.15

5 years ago

4.0.0-beta.14

5 years ago