Strongloop Loopback connector for Elasticsearch
near
queries with multi_match
? I'm trying to use and
operator but the multi_match
query has no effect on the result.{"where":{"and":[{"geo":{"near":{"lat":30.78,"lng":76.69}}},{"native":{"query":{"multi_match":{"query":"python","fields":["title","tags","description"],"type":"most_fields"}}}}]}}
loopback 4 connector for ElasticSearch.
I am working on loopback4 with Elasticsearch. I am created datasource.json file like this
{
"name": "customer",
"connector": "esv6",
"index": "index_name",
"hosts": [
{
"protocol": "http",
"host": "127.0.0.1",
"port": 9200
}
],
"apiVersion": "6.5",
"defaultSize": "100",
"requestTimeout": 30000,
"log": "trace",
"mappingType": "basedata",
"mappings": [],
"mappingProperties": {
"......."
"id": {
"type": "keyword",
"index": true
},
"docType": {
"type": "keyword",
"index": true
}
}
}
}
And my model having same id property like this
@property({
type: "string",
id: true,
generated: true,
})
id: string;
using => "loopback-connector-esv6": "^1.3.0"
but i am not able to mapping properly...not sure . because ,i am able create (POST) a model object with auto generated id (_id)..but using this id we are not able to find/fetch any data. except POST other APIS are not working..
So could you please suggest to help on this ..
how to connect elastic search using loopback4.
Hi! Have a problem with elasticsearch query
"native":
{
"sort":["_id"],
"query":{ query_string: { query: 'companyName:apple' } }
}}
no matter which query i am using in DEBUG i always get same result'{"sort":["_id"],"query":{"bool":{"must":{"match_all":{}},"filter":[{"term":{"docType":"LeadElastic"}}]}}}
this issue only when i am using "native" filter
"where" filter works ok but I need to use "query_string" and only way to use it is "native" filter
// TODO: native query support must be secured to restrict data access to request model /* if (criteria.native) { filter.body = criteria.native; // assume that the developer has provided ES compatible DSL } */
Found this in source code
@AndrewKuktenko , not planning for this now in connector as it requires us to create a property in model to hold aggregation data.
I would suggest to implement custom remote methods or a mixin for aggregation support.
You can always use esclient in your loopback code.
const myesclient = MyModel.getDataSource().connector.db;
// use es client search method for aggregationsmyesclient.search(...)