Как использовать Attachment Processor эластичного поиска с node.js - PullRequest
0 голосов
/ 23 марта 2019

Я подаю заявку на поиск слов или фраз в файлах .PDF и сделал следующий код (найден в интернете):

const elasticsearch = require('elasticsearch');
const fse = require('fs-extra')

let client = new elasticsearch.Client({
    host: "localhost:9200",
    log: ["error", "warning"]
});

client.indices.create({index: 'files'})
.then(() => {
    // create a mapping for the attachment
    return client.indices.putMapping({
        index: 'files',
        type: 'document',
        body: {
            document: {
                properties: {
                    file: {
                        type: 'attachment',
                        fields: {
                            content: {
                                type: 'string',
                                term_vector: 'with_positions_offsets',
                                store: true
                            }
                        }
                    }
                }
            }
        }
    });
});

const fileContents = fse.readFileSync('C:\\Users\\JoaoDJunior\\Downloads\\João D. Junior - rc.pdf');
const fileBase64 = new Buffer(fileContents).toString('base64');
//console.log(fileBase64);
client.create({
    index: 'files',
    type: 'document',
    id: 'somefileid',
    body: {
        file_id: 'somefileid',
        file: {
            _content: fileBase64
        }
    }
})
.catch((err) => {
    console.error('Error while creating elasticsearch record', err);
});

client.search({
    q: 'java',
    index: 'files'
}, (error, result) => {
    if (error) return console.log(error);
    console.log(result.hits);
});

Проблема в том, что я не могу получить слова внутри документа. Есть ли ошибка в моем коде, кто-нибудь может помочь?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...