GithubHelp home page GithubHelp logo

Comments (1)

Litterfeldt avatar Litterfeldt commented on June 26, 2024

"resolved" by setting up the models before establishing the connection to elastic search that creates the indexes.. The default indexes created are not allowed to be overridden and the default analyser is a tokeniser that strips away the "-".

import * as elasticsearch from "elasticsearch-odm-5";

const searchSchema = new elasticsearch.Schema({
    thingId: { type: String },
});

const model = elasticsearch.model("things", searchSchema);

const elasticSearchCRUD = async (thingId) => {
    console.log("\nCreating thing with thingId: ", thingId);
    await model.create({ thingId });

    await new Promise(res => setTimeout(res, 1000));

    let thing = await model.findOne({ thingId });

    console.log(thing);
}

const isWorking  = async () => elasticSearchCRUD("a");
const notWorking = async () => elasticSearchCRUD("a-27");


const run = async () => {
    await elasticsearch.connect({
        host: "http://localhost:9200",
        index: "my-index",
        logging: true,
    });

    await isWorking();
    await notWorking();
}

run();
$ ts-node src/test.ts

Creating thing with thingId:  a
modelInstance {
  thingId: 'a',
  createdOn: '2018-09-04T15:56:33.169Z',
  updatedOn: '2018-09-04T15:56:33.188Z',
  id: 'AWWlTLgauOXlND3DZB0-' }

Creating thing with thingId:  a-27
modelInstance {
  thingId: 'a-27',
  createdOn: '2018-09-04T15:56:34.445Z',
  updatedOn: '2018-09-04T15:56:34.467Z',
  id: 'AWWlTL0YuOXlND3DZB0_' }

from elasticsearch-odm.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.