Skip to content

Commit 499182b

Browse files
committed
Fix default operator option.
1 parent 7c77229 commit 499182b

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/aws-es.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,14 @@ AWSES.prototype.search = function(options, callback) {
290290
var qs = {};
291291
if(options.scroll) qs.scroll = options.scroll;
292292
if(options.searchType) qs.search_type = options.searchType;
293-
if(options.defaultOperator) qs.default_operator = options.defaultOperator;
294293
if(options.size) qs.size = options.size;
295294
if(options.from) qs.from = options.from;
296295
if(options.sort) qs.sort = options.sort;
297296

297+
if( is.existy(options.defaultOperator) && is.existy(options.body)
298+
&& is.existy(options.body.query) && is.existy(options.body.query.query_string))
299+
options.body.query.query_string.default_operator = options.defaultOperator;
300+
298301
var path = '/' + options.index + '/' + options.type + '/_search';
299302
path += '/?' + querystring.stringify(qs);
300303

test/lib/aws-esSpec.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('aws-es', function() {
3535
type: TYPE,
3636
id: '1',
3737
body: {
38-
title: 'first title',
38+
title: 'first post title',
3939
shares: 2
4040
}
4141
}, function(err, data) {
@@ -398,7 +398,7 @@ describe('aws-es', function() {
398398
type: TYPE,
399399
id: '2',
400400
body: {
401-
title: 'second title',
401+
title: 'second post title',
402402
shares: 10
403403
}
404404
}, function(err, data) {
@@ -603,7 +603,7 @@ describe('aws-es', function() {
603603

604604
var ops = [];
605605
ops.push({ update: { _id : '1' }});
606-
ops.push({ doc: { title: 'brand new' }});
606+
ops.push({ doc: { title: 'brand new title' }});
607607

608608
elasticsearch.bulk({
609609
index: INDEX,
@@ -923,6 +923,27 @@ describe('aws-es', function() {
923923
done();
924924
});
925925
});
926+
927+
it('should succeed with defaultOperator AND', function(done) {
928+
this.timeout(20000);
929+
930+
elasticsearch.search({
931+
index: INDEX,
932+
type: TYPE,
933+
body: {
934+
query: {
935+
query_string: {
936+
query: 'second title'
937+
}
938+
}
939+
},
940+
defaultOperator: 'AND'
941+
}, function(err, data) {
942+
expect(err).to.be.null;
943+
expect(data.hits.hits.length).to.be.equal(1);
944+
done();
945+
});
946+
});
926947
});
927948

928949
describe('scroll', function() {

0 commit comments

Comments
 (0)