# humane-indexer

> Indexer module for Humane Discovery

Latest version **2.0.3** (published 2016-12-24) · LGPL license · 0 weekly downloads

## Install

```sh
npm install humane-indexer
pnpm add humane-indexer
yarn add humane-indexer
bun add humane-indexer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2016-12-24 |
| First published | 2016-03-17 |
| Weekly downloads | 0 |
| License | LGPL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Known vulnerabilities | 0 (+13 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Shailendra Sharma |
| Maintainers | snow01 |

## Links

- npm: https://www.npmjs.com/package/humane-indexer
- Repository: https://github.com/360fy/humane-indexer
- Homepage: https://github.com/360fy/humane-indexer#readme
- Issues: https://github.com/360fy/humane-indexer/issues
- npm.io page: https://npm.io/package/humane-indexer

## Dependencies (12)

- [joi](https://npm.io/package/joi.md) 9.2.0
- [md5](https://npm.io/package/md5.md) 2.2.1
- [chalk](https://npm.io/package/chalk.md) 1.1.3
- [events](https://npm.io/package/events.md) 1.1.1
- [lodash](https://npm.io/package/lodash.md) 4.17.2
- [moment](https://npm.io/package/moment.md) 2.16.0
- [bluebird](https://npm.io/package/bluebird.md) 3.4.6
- [semlocks](https://npm.io/package/semlocks.md) 1.3.0
- [redislock](https://npm.io/package/redislock.md) 1.2.0
- [performance-now](https://npm.io/package/performance-now.md) 0.2.0
- [humane-node-commons](https://npm.io/package/humane-node-commons.md) 1.4.2
- [command-line-boilerplate](https://npm.io/package/command-line-boilerplate.md) 1.1.8

## Recent versions

- 2.0.3 (latest) — 2016-12-24
- 2.0.2 — 2016-12-22
- 2.0.1 — 2016-11-28
- 2.0.0 — 2016-11-17
- 1.12.5 — 2016-11-10
- 1.12.4 — 2016-09-14
- 1.12.3 — 2016-09-12
- 1.12.2 — 2016-09-12
- 1.12.1 — 2016-09-12
- 1.12.0 — 2016-09-05
- 1.11.0 — 2016-08-09
- 1.10.1 — 2016-07-28
- 1.9.5 — 2016-07-19
- 1.9.4 — 2016-07-19
- 1.9.3 — 2016-07-19
- … 40 more at https://npm.io/package/humane-indexer/versions

## README

# humane-indexer

## APIs

>
>Note:
>    * Indexer APIs are available at: `http://<server-url>/:instanceName/indexer/api`.
>    * All types must be valid index types defined in configuration.
>    * BODY must be valid `JSON`.
>    * All requests shall have `Content-Type` header as: `Content-Type: application/json`

### Add

This method adds document of given type.

###### **Method 1**

- TYPE  : `POST`

- URL   : `/add`

- BODY  : `{type: <type>, doc: <data>}`

- SUCCESS RESPONSE  : 

    - Http Status Code: 200 or 201
    
    - Sample Response Body :

      ```
      {
        "_id": "18473",
        "_type": "abcType",
        "_index": "xyzIndex",
        "_version": 5,
        "_statusCode": 201,
        "_status": "SUCCESS",
        "_operation": "ADD",
        "serviceTimeTaken": "127.377"
      }
      ```

- ERROR RESPONSES   : See Common Error Scenarios

    - Case: Document already exists
    
        - Http Status Code: 404
        
        - Sample Response Body :
    
          ```json
          {
            "_id": "18473",
            "_type": "abcType",
            "_index": "xyzIndex",
            "_statusCode": 404,
            "_status": "FAIL",
            "_failCode": "EXISTS_ALREADY",
            "_operation": "ADD",
            "serviceTimeTaken": "70.075"
          }
          ```
    
    - See Common Error Scenarios

###### **Method 2**

- TYPE  : `PUT`

- URL   : `/:type`

- BODY  : `{doc: <data>}`

- SUCCESS RESPONSE  : Same as method 1

- ERROR RESPONSES   : Same as method 1

### Full Update

This method does full update of document of given type and id.

###### **Method 1**

- TYPE  : `POST`

- URL   : `/update`

- BODY  : `{type: <type>, id: <id>, doc: <data>}`

- SUCCESS RESPONSE  :

    - Http Status Code: 200
    
    - Sample Response Body :

      ```
      {
        "_id": "18473",
        "_type": "abcType",
        "_index": "xyzIndex",
        "_version": 1,
        "_statusCode": 200,
        "_status": "SUCCESS",
        "_operation": "UPDATE",
        "serviceTimeTaken": "255.350"
      }
      ```

- ERROR RESPONSES   :

    - Case: Not found ID
    
        - Http Status Code: 404
        
        - Sample Response Body :
    
          ```json
          {
            "_id": "18473",
            "_type": "abcType",
            "_index": "xyzIndex",
            "_statusCode": 404,
            "_status": "FAIL",
            "_failCode": "NOT_FOUND",
            "_operation": "UPDATE",
            "serviceTimeTaken": "70.075"
          }
          ```
    
    - See Common Error Scenarios
  
###### **Method 2**

- TYPE  : `POST`

- URL   : `/:type/:id`

- BODY  : `{doc: <data>}`

- SUCCESS RESPONSE  : Same as method 1

- ERROR RESPONSES   : Same as method 1

### Merge

This method merges given data with existing data of given type and id.

- TYPE  : `POST`

- URL   : `/merge`

- BODY  : `{type: <type>, id: <id>, doc: <data>}`

- SUCCESS RESPONSE  :

    - Http Status Code: 200
    
    - Sample Response Body :

      ```
      {
        "_id": "18473",
        "_type": "abcType",
        "_index": "xyzIndex",
        "_version": 1,
        "_statusCode": 200,
        "_status": "SUCCESS",
        "_operation": "PARTIAL_UPDATE",
        "serviceTimeTaken": "133.818"
      }
      ```

- ERROR RESPONSES   :

    - Case: Not found ID
    
        - Http Status Code: 404
        
        - Sample Response Body :
    
          ```json
          {
            "_id": "18479",
            "_type": "abcType",
            "_index": "xyzIndex",
            "_statusCode": 404,
            "_status": "FAIL",
            "_failCode": "NOT_FOUND",
            "_operation": "MERGE",
            "serviceTimeTaken": "16.548"
          }
          ```
    
    - See Common Error Scenarios

### Upsert

This method adds data of given type if it does not exist, else makes full update.

###### **Method 1**

- TYPE  : `POST`

- URL   : `/upsert`

- BODY  : `{type: <type>, doc: <data>}`

- SUCCESS RESPONSE  : For new document: add response, for existing document: update response

- ERROR RESPONSES   : See Common Error Scenarios

###### **Method 2**

- TYPE  : `POST`

- URL   : `/:type`

- BODY  : `{doc: <data>}`

- SUCCESS RESPONSE  : Same as method 1

- ERROR RESPONSES   : Same as method 1

### Remove

This method removes document of given type and id.

###### **Method 1**

- TYPE  : `POST`

- URL   : `/remove`

- BODY  : `{type: <type>, id: <id>}`

- SUCCESS RESPONSE  :

    - Http Status Code: 200
    
    - Sample Response Body :
    
      ```
      {
        "_id": "18473",
        "_type": "abcType",
        "_index": "xyzIndex",
        "_version": 4,
        "found": true,
        "_statusCode": 200,
        "_status": "SUCCESS",
        "_operation": "REMOVE",
        "serviceTimeTaken": "122.236"
      }
      ```

- ERROR RESPONSES   :
  
    - Case: Not found ID
    
        - Http Status Code: 404
        
        - Sample Response Body :
    
          ```json
          {
            "_id": "18473",
            "_type": "abcType",
            "_index": "xyzIndex",
            "_statusCode": 404,
            "_status": "FAIL",
            "_operation": "REMOVE",
            "_failCode": "NOT_FOUND",
            "serviceTimeTaken": "84.184"
          }
          ```
    
    - See Common Error Scenarios
    
###### **Method 2**

- Type  : `DELETE`

- URL   : `/:type/:id`

- SUCCESS RESPONSE  : Same as method 1

- ERROR RESPONSES   : Same as method 1

### Common Error Scenarios

- Case: Undefined Type - when type is not specified
    - Http Status Code: 400
    
    - Sample Response Body :
    
      ```json
      {
        "_statusCode": 400,
        "_errorCode": "VALIDATION_ERROR",
        "_status": "ERROR",
        "details": {
          "code": "UNDEFINED_TYPE"
        },
        "_errorId": 1458790949474
      }
      ```

- Case: Unrecognized Type - when type is not among the configured

    - Http Status Code: 400
    
    - Sample Response Body :
    
      ```json
      {
        "_statusCode": 400,
        "_errorCode": "VALIDATION_ERROR",
        "_status": "ERROR",
        "details": {
          "code": "UNRECOGNIZED_TYPE",
          "type": "XYZ"
        },
        "_errorId": 1458790974877
      }
      ```
         
- Case: Undefined ID - when ID is not specified or can not be calculated

    - Http Status Code: 400
    
    - Sample Response Body :
    
      ```json
      {
        "_statusCode": 400,
        "_errorCode": "VALIDATION_ERROR",
        "_status": "ERROR",
        "details": {
          "code": "UNDEFINED_ID"
        },
        "_errorId": 1458748607506
      }
      ```
  
- Case: Internal Service Error - when there is some internal service error

    - Http Status Code: 500
    
    - Sample Response Body :
    
      ```json
      {
        "_statusCode": 500,
        "_errorCode": "INTERNAL_SERVICE_ERROR",
        "_status": "ERROR",
        "_errorId": 1458819775194
      }
      ```

---
_Source: https://npm.io/package/humane-indexer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
