node.js - Elasticsearch english language analyzer with nodejs -
first time trying implement elastic search using aws hosted service nodejs. referred official docs , came this:
//1. create index client.indices.create({ index: 'products' }); //2. mapping client.indices.putmapping({ index: 'products', type: 'products', body: { properties: { 'product_name': { 'type': 'string', "analyzer": "english" }, 'product_description': { 'type': 'string', "analyzer": "english" } } } }); //3. import documents.. product_name: testing //4. search client.search({ index: 'products', type: 'products', q: keywords, analyzer: 'english', size: 10 });
now, if search 'testing' or 'token testing', returns 1 result. if test passing 'test' or 'tist' keyword, seems analyzer isn't picking , no results.
updated: added analyzer: 'english' according @val answer, still no results 'test' or 'tist'.
that's because when using q
parameter, query_string
query made , default analyzer of input string standard
analyzer.
you have 2 choices here:
a. include field name in query string:
client.search({ index: 'products', type: 'products', q: 'product_name:' + keywords, <--- modify size: 10 });
b. specify english
query-time analyzer produce same tokens has been indexed:
client.search({ index: 'products', type: 'products', q: keywords, analyzer: 'english', <--- or add size: 10 });
Comments
Post a Comment