dimitrov-adrian / directus-extension-searchsync

Simple Directus 9 extension that sync content with remote search engine.
MIT License
116 stars 27 forks source link

Getting bad request during initialization of directus #7

Closed jfrancarioInera closed 3 years ago

jfrancarioInera commented 3 years ago

Getting this error when trying to post the initial collections to elasticsearch.

SEARCHSYNC {
  action: 'UPDATE',
  collection: 'tappe',
  id: 5,
  error: Error: Request failed with status code 400
      at createError (/home/james/directus-test/extensions/hooks/directus-extension-searchsync-main/node_modules/axios/lib/core/createError.js:16:15)
      at settle (/home/james/directus-test/extensions/hooks/directus-extension-searchsync-main/node_modules/axios/lib/core/settle.js:17:12)
      at IncomingMessage.handleStreamEnd (/home/james/directus-test/extensions/hooks/directus-extension-searchsync-main/node_modules/axios/lib/adapters/http.js:260:11)
      at IncomingMessage.emit (events.js:387:35)
      at endReadableNT (internal/streams/readable.js:1317:12)
      at processTicksAndRejections (internal/process/task_queues.js:82:21) {
    config: {
      url: 'http://localhost:9200/directus2/_search/tappe/_doc/5',
      method: 'post',
      data: '{"nome":"fewad","tipo":"Monumento"}',
      headers: [Object],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus]
    },
    request: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [Socket],
      _header: 'POST /directus2/_search/tappe/_doc/5 HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json\r\n' +
        'User-Agent: axios/0.21.1\r\n' +
        'Content-Length: 35\r\n' +
        'Host: localhost:9200\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'POST',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/directus2/_search/tappe/_doc/5',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'localhost',
      protocol: 'http:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    response: {
      status: 400,
      statusText: 'Bad Request',
      headers: [Object],
      config: [Object],
      request: [ClientRequest],
      data: [Object]
    },
    isAxiosError: true,
    toJSON: [Function: toJSON]
  }
}

configfile:

module.exports = {
    server: {
        type: "elasticsearch",
        host: "http://localhost:9200/directus2/_search",

    },
    reindexOnStart: true,
    collections: {
        viaggi: {
            filter: {

            },
            fields: [
                "nome",
                "durata_h",
                "difficolta",

            ],
            transform: formatter,
        },
        tappe: {
            filter: {

            },
            fields: ["nome", "tipo"],
            transform: formatter,
        },
    },
};

function formatter(value, { flattenObject }) {
    value = flattenObject(value);
    return value;
}

Btw is this extension valid for production purposes?

dimitrov-adrian commented 3 years ago

What is the elasticsearch version you have installed?

jfrancarioInera commented 3 years ago

This one:

"version" : {
    "number" : "7.13.4",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "c5f60e894ca0c61cdbae4f5a686d9f08bcefc942",
    "build_date" : "2021-07-14T18:33:36.673943207Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  }
dimitrov-adrian commented 3 years ago

It should be fixed now


@jfrancarioInera your config seems to be wrong defining the host

Use:

host: "http://localhost:9200/directus",
jfrancarioInera commented 3 years ago

@dimitrov-adrian Hi sorry for bothering you again. Reinstalled the extension following the new readme, but i get a strange behavior. Changed the host to http://localhost:9200/directus but only one collection gets saved in elasticsearch index.

directus-extension-searchsync Cannot update viaggi/1. Error: Request failed with status code 400
directus-extension-searchsync Cannot update viaggi/2. Error: Request failed with status code 400
directus-extension-searchsync Cannot update viaggi/3. Error: Request failed with status code 400
directus-extension-searchsync Cannot update viaggi/4. Error: Request failed with status code 400
directus-extension-searchsync Cannot update viaggi/5. Error: Request failed with status code 400
directus-extension-searchsync Cannot update viaggi/6. Error: Request failed with status code 400

This is what I get if I query elasticsearch: GET http://localhost:9200/directus/_search

Answer ``` { "took": 37, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 6, "relation": "eq" }, "max_score": 1.0, "hits": [ { "_index": "directus", "_type": "tappe", "_id": "1", "_score": 1.0, "_source": { "nome": "Cavalieri", "tipo": "piazza" } }, { "_index": "directus", "_type": "tappe", "_id": "2", "_score": 1.0, "_source": { "nome": "Massaciuccoli", "tipo": "lago" } }, { "_index": "directus", "_type": "tappe", "_id": "3", "_score": 1.0, "_source": { "nome": "Villa Flora", "tipo": "piazza" } }, { "_index": "directus", "_type": "tappe", "_id": "4", "_score": 1.0, "_source": { "nome": "test1", "tipo": "Monumento" } }, { "_index": "directus", "_type": "tappe", "_id": "5", "_score": 1.0, "_source": { "nome": "fewad", "tipo": "Monumento" } }, { "_index": "directus", "_type": "tappe", "_id": "6", "_score": 1.0, "_source": { "nome": "tappaprova", "tipo": "Parco" } } ] } } ```

Only the collection 'tappe' gets saved. The collection 'viaggi' has a one to many relationship with 'tappe'. Anyway, it happened the opposite aswell, the 'viaggi' collection got saved, but not 'tappe.

the configuration file is the same except the host.

Configuration ```javascript module.exports = { server: { type: "elasticsearch", host: "http://localhost:9200/directus", }, reindexOnStart: true, collections: { viaggi: { filter: { }, fields: [ "nome", "durata_h", "difficolta", ], transform: formatter, }, tappe: { filter: { }, fields: ["nome", "tipo"], transform: formatter, }, }, }; function formatter(value, { flattenObject }) { value = flattenObject(value); return value; } ```
keniobats commented 1 year ago

@jfrancarioInera Did you manage to solve this? I'm facing the same issue with ELK 8.4.2