add mapping of raw field with english analyzer
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
76f7e27468
commit
b58ffd8c19
|
@ -18,6 +18,17 @@ const CONSOLE_DEFAULTS = {
|
|||
chunkSize: 50
|
||||
};
|
||||
|
||||
const INDEX_MAPPING = {
|
||||
properties: {
|
||||
raw: {
|
||||
type: "text",
|
||||
fields: {
|
||||
english: { type: "text", analyzer: "english" }
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
const INDEXED_PROPERTIES = [
|
||||
'title',
|
||||
'excerpt',
|
||||
|
@ -31,14 +42,16 @@ const INDEXED_PROPERTIES = [
|
|||
function bulkCallback(err, resp) {
|
||||
/* if there's an error show it */
|
||||
if (err) {
|
||||
this.log.error(`${prefix} %s`, err);
|
||||
this.log.error(`${prefix} Status: %s Error: %s`, err.status, err.message);
|
||||
this.log.error(`${prefix} >> ElasticSearch request failed.`);
|
||||
process.exit(1);
|
||||
}
|
||||
/* if there are errors in specific operations show them */
|
||||
if (resp.errors) {
|
||||
each(resp.items, (item) => {
|
||||
if (item.status != 200) {
|
||||
this.log.error(item);
|
||||
this.log.error('Error: %s', item);
|
||||
console.dir(item)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
@ -116,6 +129,23 @@ module.exports = function(args, callback) {
|
|||
process.exit(1);
|
||||
})
|
||||
})
|
||||
.then(async () => { /* create index if missing, set mappings */
|
||||
/* check if index exists */
|
||||
try {
|
||||
await es.indices.getMapping({index: conf.index});
|
||||
} catch(e) { /* index doesn't exist */
|
||||
await es.indices.create({index: conf.index});
|
||||
}
|
||||
/* update index field mappings */
|
||||
await es.indices.putMapping({
|
||||
index: conf.index, type: '_doc', body: INDEX_MAPPING,
|
||||
})
|
||||
.catch((error) => {
|
||||
err('%s', error);
|
||||
err('>> Unable to configure index mappings!')
|
||||
process.exit(1)
|
||||
});
|
||||
})
|
||||
.then(() => { /* load all hexo documents */
|
||||
return hexo.load();
|
||||
})
|
||||
|
@ -153,15 +183,15 @@ module.exports = function(args, callback) {
|
|||
**/
|
||||
info('%d pages and posts to index.', cleanedPosts.length);
|
||||
return cleanedPosts.map((post) => [
|
||||
{ index: { _index: conf.index, _type: 'post', _id: sha1(post.url)} },
|
||||
{ index: { _index: conf.index, _type: '_doc', _id: sha1(post.url)} },
|
||||
post, /* first object in array is the action, second is the doc */
|
||||
]);
|
||||
})
|
||||
.then((actionsAndPosts) => { /* flatten arrays of arrays into single array */
|
||||
return [].concat.apply([], actionsAndPosts);
|
||||
})
|
||||
.then((postsBatch) => { /* batch upload posts to ElasticSearch */
|
||||
es.bulk({body: postsBatch}, bulkCallback.bind(hexo))
|
||||
.then(async (postsBatch) => { /* batch upload posts to ElasticSearch */
|
||||
await es.bulk({body: postsBatch}, bulkCallback.bind(hexo))
|
||||
})
|
||||
.then(() => {
|
||||
info('Indexing done.');
|
||||
|
|
Loading…
Reference in New Issue