0

I made elastic.js build dynamic query like this:

{
    "size": 15,
    "query": {
        "bool": {
            "must": [
                { "term": { "tag": { "term": "rocket" } } },
                { "term": { "name": { "term": "space" } } }
            ],
            "should": [
                { "wildcard": { "place": { "value": "Moo*" } } }
            ]
        }
    }
}

Elastic.js code for this is ( Translator ):

ejs.Request()
    .size(15)
    .query(
      ejs.BoolQuery()
        .must(ejs.TermQuery('tag', 'rocket'))
        .must(ejs.TermQuery('name', 'space'))
        .should(ejs.WildcardQuery('place', 'Moo*'))
)

It works great, I am happy and I would like it to be like that. But I realized that I need to add an option to perform this query with OR condition, instead of AND as is now.

It should find documents that match any of provided conditions.

And that task leaves me with no clues (even about DSL that will complete this purpose).

I have looked at OrFilter but I have no idea on how to use it right (especially with elasticJS). Any solid source of information on elastic/js will be greatly appreciated

Dmitry Evseev
  • 11,533
  • 3
  • 34
  • 48

2 Answers2

1

You can put all your clauses in the should section of your bool query.

Regarding elastic.js I personally think it's a great piece of software, really well documented as well. Have a look at its API documentation.

javanna
  • 59,145
  • 14
  • 144
  • 125
0
var r = ejs.Request({indices: index, types: type}),
    boolQ = ejs.BoolQuery();

boolQ.should(ejs.FieldQuery("DEAL_NAME","value")).defaultOperator("AND"));
boolQ.should(ejs.TermQuery( "DEAL_MOTTO","value"));                     
boolQ.should(ejs.FieldQuery("dealaddresses.CITY","value").defaultOperator("AND"));

r.query(boolQ);
Gaurav joshi
  • 1,743
  • 1
  • 14
  • 28