Skip to content

Commit

Permalink
es search improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hkulekci committed Aug 9, 2018
1 parent a82091b commit b2d8f8e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,23 @@ PUT products
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
"number_of_replicas": 0,
"analysis": {
"analyzer": {
"autocomplete_analyzer" : {
"type" : "custom",
"tokenizer": "standard",
"filter": ["lowercase", "autocomplete_filter"]
}
},
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 10
}
}
}
}
}
Expand All @@ -49,10 +65,24 @@ PUT products/product/_mapping
{
"properties": {
"name": {
"type": "text"
"type": "text",
"fields": {
"autocomplete": {
"type": "text",
"analyzer": "autocomplete_analyzer",
"search_analyzer": "standard"
}
}
},
"description": {
"type": "text"
"type": "text",
"fields": {
"autocomplete": {
"type": "text",
"analyzer": "autocomplete_analyzer",
"search_analyzer": "standard"
}
}
},
"quantity": {
"type": "long"
Expand All @@ -75,7 +105,14 @@ PUT products/product/_mapping
"type": "long"
},
"name": {
"type": "keyword"
"type": "keyword",
"fields": {
"autocomplete": {
"type": "text",
"analyzer": "autocomplete_analyzer",
"search_analyzer": "standard"
}
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions services/productSearchService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ var db = require('./../libraries/elasticsearch');

exports.getRecords = function(params, callback) {
body = {
query: {
},
query: {},
size: 50
};

Expand All @@ -17,8 +16,9 @@ exports.getRecords = function(params, callback) {

if (params.keyword) {
body.query.query_string = {
"fields": ["name^4", "description^2", "categories.name^3"],
"query": params.keyword
"fields": ["name.autocomplete^10", "description.autocomplete^2", "categories.name.autocomplete^3"],
"query": params.keyword,
"default_operator": "AND"
};
}

Expand Down

0 comments on commit b2d8f8e

Please sign in to comment.