-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnestedCategory.js
36 lines (34 loc) · 1.26 KB
/
nestedCategory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const keyword = { query_string: { query: 'nike shoes' } };
const filter = { bool: { should: [
{ bool: { must: [
{ range: { air: { gte: 1517795104902 } } },
{ term: { sellType: 'owner' } },
{ range: { price: { gte: 80, lte: 150 } } },
{ term: { locations: 'nation_wide' } },
{ term: { locCount: 1 } },
{ term: { topics: 'shoes' } }
] } },
{ bool: { must: [
{ range: { air: { gte: 1517795104902 } } },
{ term: { sellType: 'owner' } },
{ range: { price: { gte: 80, lte: 150 } } },
{ term: { locations: 'nation_wide' } },
{ term: { locations: 'california' } },
{ term: { topics: 'shoes' } }
] } }
] } };
post.search({ bool: {
must : keyword,
filter : filter,
}}, {
size : 10, // number of returned results
from : 0, // return from result 0. These two can be apply to create paging
sort : { createdAt: { order: 'desc' } }, // sort your result
_source: ['title','url','price','photos','board'], // control returned fields
}, function(err, searchRes) {
if(err) { cb(err, null) } else { cb(null, {
found : searchRes.hits.total,
searchTime : searchRes.took,
resList : searchRes.hits.hits
})}
});