1

In my NodeJs API, I haven't been able to query a meta engine that is composed by multiple single engines. I need to get documents filtered by a list of Ids.

I'm using @elastic/enterprise-search package version 8.6.0

When I try listing all the documents it works, I get all of them. But I haven't been able to get by ids.

I tried using the client method getDocuments(), but it doesn't find anything and returns a list of nulls. I try something like this but still get errors:

const { Client } = require('@elastic/enterprise-search');

const client = () =>
    new Client({
        url: process.env.ELASTIC_SEARCH_URL,
        auth: {
            token: process.env.ELASTIC_SEARCH_KEY,
        },
    });

const searchItemsFromMetaEngineAppSearch = async (engine, idList) => {
    const requests = idList.map((id) => {
        return {
            index: engine,
            body: {
                query: {
                    ids: {
                        values: [id],
                    },
                },
            },
        };
    });

    const documents = await client().app.search({
        body: requests,
    });
    return documents;
};

There's not much info in the web about querying meta engines.

TylerH
  • 20,799
  • 66
  • 75
  • 101
letie
  • 704
  • 2
  • 10
  • 20
  • The error message that you are seeing: `Could not find engine` means search request couldn't find the specified engine. It might happen because of engine name is misspelled or engine doesn't exist on the server – Farkhod Abdukodirov Apr 30 '23 at 00:29
  • @FarkhodAbdukodirov However if I try with the getDocuments() method it does reach the engine and I can see logs in elastic search side... But it only returns nulls – letie May 01 '23 at 12:26
  • If you can see logs on Elasticsearch side, probably issue is related to how you are constructing the `getDocuments`, which doesn't support queries in the same way that the `search` method does. Try the following: `const documents = await client().app.getDocuments({engineName: engine, ids: idList}); return documents;` – Farkhod Abdukodirov May 01 '23 at 23:30
  • @FarkhodAbdukodirov I was constructing it just like that. The problem was that I was using the documents' ids, and with meta engines you have to use the "scoped" ids (https://www.elastic.co/guide/en/app-search/current/meta-engines-guide.html#meta-engines-guide-scoped-ids) – letie May 02 '23 at 13:27
  • The meta tag is not about meta engines. Please do not misuse it here. – TylerH May 05 '23 at 21:28

1 Answers1

1

Turns out that the ids of elements in a meta engine are not the same as elements in a single engine.

In a single engine you'd do something like this:

const documents = await client().app.getDocuments({
     engineName: engine, 
     ids: [ "id" ]
});

In a meta engine you have to use the "scoped id" ("{engine}|{id}") of the element to get by id, using name of the engine to which they belong:

const documents = await client().app.getDocuments({
     engineName: engine, 
     ids: [ "engineName|id" ]
});

(https://www.elastic.co/guide/en/app-search/current/meta-engines-guide.html#meta-engines-guide-scoped-ids)

letie
  • 704
  • 2
  • 10
  • 20