loopbackio / loopback-connector-elastic-search

Strongloop Loopback connector for Elasticsearch
MIT License
78 stars 56 forks source link

support for multi_match queries #62

Closed emckean closed 7 years ago

emckean commented 7 years ago

is it possible for this connector to support multi_match queries, e.g.:

{
  "multi_match" : {
    "query":    "this is a test", 
    "fields": [ "subject", "message" ] 
  }
}

I see in the notes that there is a mention of multi_field mapping:

"name" : {
    "type" : "multi_field",
    "fields" : {
        "name" : {"type" : "string", "index" : "not_analyzed"},
        "native" : {"type" : "string", "index" : "analyzed"}
    }
}
...
// this will treat 'George Harrison' as 'George Harrison' in a search
User.find({order: 'name'}, function (err, users) {..}
// this will treat 'George Harrison' as two tokens: 'george' and 'harrison' in a search
User.find({order: 'name', where: {'name.native': 'Harrison'}}, function (err, users) {..}

But I don't see how to do a multi_field query. When I run a query from the Explorer I see:

{
    "sort": [
      "_id"
    ],
    "query": {
      "bool": {
        "must": [
          {
            "match": {
              "question.text": "theory"
            }
          }
        ]
      }
    }
  }

Any pointers gratefully appreciated -- I'm writing this up for a webinar and would like to be able to use some of Elasticsearch's more interesting features with LoopBack.

emckean commented 7 years ago

Hi! I figured it out -- you have to use the 'native' filter, e.g.

{"native": {
    "sort": [
      "_id"
    ],
    "query": {
    "multi_match": {
      "query": "theory",
      "fields": [ 
        "question",
        "question.text"
      ],
      "type": "most_fields" 
    }
  }
}
}