elasticsearch api in angular 2 application - api

I am not sure , how to use elasticsearch API avaialble in below link in angular application.
https://www.elastic.co/guide/en/elasticsearch/reference/current/search.html
I have gone through the below sit for using elasticsearch services.But for other functionality like multi field search, conditional search, pagination with first and last pages, i didnt get any idea how to proceed.
http://javasampleapproach.com/frontend/angular/angular-4-elasticsearch-example-quick-start-how-to-add-elasticsearch-js#comment-3537
Please kindly share any links or guide me using elastic search in angular cli (angular 2) application.

There is a javascript client available too.
https://www.npmjs.com/package/elasticsearch
npm install elasticsearch --save
Its typings are available from definitelyTypes
npm install #types/elasticsearch --save
Then you can directly use in your angular application
Example :
To create ElasticSearch client
...
import { Client } from 'elasticsearch';
...
this.esClient = new Client({
host: 'elastic-url'
});
...
everything is there in the official client For features such as pagination, conditional search you have to constuct your query properly before passing.
Example Query:
{
"query": {
"bool": {
"should": [
{
"term": {
"param2": "HUMAN"
}
},{
"match": {
"param1": "param1"
}
}
]
}
}
Example Usage:
client.search({
index: 'masterindex',
body: {
"size":0,
"query": esQuery,
"aggs": aggOBj
}
},(error, response)=> {})

Related

Production build orderCore is missing

I had to manually upgrade from 3.2 to 4.2 and because I am developing a Angular library, I could not use the schematics to perform the update.
I have got it working on the development build. We are developing a feature library that targets the checkout (Payment Page and Order Confirmation Page) and it works fine.
With the production build (ng build --configuration production), the payment page works fine, but the Order Confirmation page is not working. it complains that orderCore feature is not configured properly.
Note: we are being redirected from an external site, back to the order confirmation page (after authorization). When the page loads, it shows the following error in the log and show a broken my account page.
core.js:6498 ERROR Error: Feature orderCore is not configured properly
at FacadeFactoryService.getResolver (spartacus-core.js:24825)
at FacadeFactoryService.create (spartacus-core.js:24867)
at facadeFactory (spartacus-core.js:24898)
at orderReturnRequestFacadeFactory (spartacus-order-root.js:13)
at Object.factory (spartacus-order-root.js:37)
at R3Injector.hydrate (core.js:11457)
at R3Injector.get (core.js:11276)
at NgModuleRef$1.get (core.js:25352)
at Object.get (core.js:25066)
at lookupTokenUsingModuleInjector (core.js:3354)
Anyone has an idea if we are missing some configuration in the feature modules?
import { NgModule } from '#angular/core';
import { checkoutTranslationChunksConfig, checkoutTranslations } from '#spartacus/checkout/assets';
import { CHECKOUT_FEATURE, CheckoutRootModule } from '#spartacus/checkout/root';
import { CmsConfig, I18nConfig, provideConfig } from '#spartacus/core';
#NgModule({
declarations: [],
imports: [
CheckoutRootModule,
],
providers: [provideConfig({
featureModules: {
[CHECKOUT_FEATURE]: {
module: () =>
import('#spartacus/checkout').then((m) => m.CheckoutModule),
}
},
} as CmsConfig),
provideConfig({
i18n: {
resources: checkoutTranslations,
chunks: checkoutTranslationChunksConfig,
},
} as I18nConfig)
]
})
export class CheckoutFeatureModule {
}
My colleague has provided a proposal:
If you want to use Spartacus Order library, you need to create "order-feature.module.ts" for it. And by default core is bundled together with components. So, in your configuration, you need have this set: "[ORDER_CORE_FEATURE]: ORDER_FEATURE". So, the config is something like this:
const config: CmsConfig = {
featureModules: {
[ORDER_FEATURE]: {
cmsComponents: [
....
],
},
// by default core is bundled together with components
[ORDER_CORE_FEATURE]: ORDER_FEATURE,
},
};

Google Analytics doesn't work in my vuepress project

Now I hava a vuepress project,
I am trying to use google analytic to track the flow of it.
But it seems there are some problem between my project and google analytic
I already follow the Document Guide(
https://vuepress.vuejs.org/plugin/official/plugin-google-analytics.html)
to use yarn add -D #vuepress/plugin-google-analytics
rather than npm install -D #vuepress/plugin-google-analytics
and also add the plugin to my config
plugins: [
'vuepress-plugin-mathjax',
{
target: 'svg',
macros: {
'*': '\\times',
},
},
'latex',
'#vuepress/google-analytics',
{
'ga': 'UA-157347770-2',
}
],
But it still nothing catch by google analytics.
Is there anyone has the same problem or similiar one before?
Thanks for anyone read
The declaration of plugin is wrong.
You have two options to declare the plugin: Babel Style or Object Style.
Babel style:
module.exports = {
plugins: [
['#vuepress/plugin-google-analytics', { ga: 'XX-000000000-0' }],
],
};
Object style:
module.exports = {
plugins: {
'#vuepress/plugin-google-analytics': {
ga: 'XX-000000000-0',
},
},
};
For more details, please see the documentation: https://vuepress.vuejs.org/plugin/using-a-plugin.html#babel-style

How can I use Hyperlink Assertion using botium asserter for chatbot developed using watson?

I have Bot text response including hyper link. I want to put assertion for that hyperlink using botium bindning and botium asserter. How can I implement it?
e.g. bot response set in watson dialog (Text Response)
"Sure I can help you with. Please click Here
on above example I want to assert for google link.
Install the Botium Hyperlink Asserter
npm install --save botium-asserter-basiclink
Adapt your botium.json
{
"botium": {
"Capabilities": {
....
"ASSERTERS": [
{
"ref": "HASLINK",
"src": "botium-asserter-basiclink"
}
]
}
}
}
Use the asserter in your convo file
...
#bot
HASLINK www.google.com
...
See the Sample on Github

Where can I get documentation on how to fetch data with Apollo and GraphQL?

I've been able to create a GraphQL server that fetches data from a local MySQL database successfuly.
If I run a query in localhost:4000/graphiql, e.g.
{
allAuthors {
id
firstName
}
}
I get a correct output as below
{
"data": {
"allAuthors": [
{
"id": 24,
"firstName": "Rosalee"
},
{
"id": 83,
"firstName": "Adeline"
}
]
}
}
Now I want to use the data on my React-Native e.g. fetch the first names and display them on the app. However I can't seem to find any useful documentation on how to use Apollo with React-Native. I can only seem to find for React and Apollo. Can someone help me get the documentation or useful tutorials on how to fetch data with Apollo and React-Native?
Thanks.
Official Documentation for apollo GraphQL, it's same for both react and react-native
https://www.apollographql.com/docs/react/

Enable Full Text Search in Apache CouchDB

I have followed the blog entry here to enable full text search https://developer.ibm.com/dwblog/2015/text-search-apache-couchdb/#.Vly24SCrQbV
I have everything correctly set up, and have also tried with other peoples docker images.
How do you set up a search? What documents are needed.
I have created a database called cats with one document
{
"_id": "6f35d75b476517e2fc0b3eb12c000e72",
"_rev": "1-c9a6b4734c83287499e8bbd6d1339050",
"name": "tibbles"
}
And a design/view
{
"_id": "_design/cat_look",
"_rev": "1-aae457e6edf5e4a3f69357e5a2160fcc",
"views": {
"kitty_name": {
"map": "function (doc) {\n index(\"kittyName\", doc.name, {\"store\": true});\n}"
}
},
"language": "javascript"
}
If I go to http://localhost:15984/cats/_design/cat_look/_search/kitty_name?q="*"
I get
{"error":"not_found","reason":"kitty_name not found."}
Thanks for any help on this, I am very lost.
A Lucene search index is set up differently to how a Map Reduce view is done. In your code, it looks like you've tried to use a Map Reduce view. For Lucene, first you need to set up an index:
{
"_id": "_design/Cat_look",
"indexes": {
"kitty_name": {
"index": "function(doc){ ... }"
}
}
}
Consult Cloudant's docs on the subject: https://console.bluemix.net/docs/services/Cloudant/api/search.html#search
Thanks for your help, you are right I set up the Lucene search index incorrectly. Here is the code to get a simple example working for anyone else lost.
If you have docker setup
docker run -d -p 15984:15984 ncheaz/couchdb:search
to get couchdb search on local port 15984
The document to search
{
"_id": "6f35d75b476517e2fc0b3eb12c000e72",
"_rev": "1-c9a6b4734c83287499e8bbd6d1339050",
"name": "tibbles"
}
The Search Index.
Create a new document, not a new view.
{
"_id": "_design/cat_look",
"_rev": "2-23f6ab0606a603cbef04653d167585d4",
"views": {},
"language": "javascript",
"indexes": {
"kitty_name": {
"analyzer": "simple",
"index": "function (doc) {if (doc.name) {index(\"name\", doc.name, {\"store\":true}); }}"
}
}
}
The url to search for the cats name is
http://localhost:15984/cats/_design/cat_look/_search/kitty_name?q=name:tibbl*
note that kitty_name is the name of the _search and name is the index name.
I recommend anyone struggling to get this working to create a free trial account on IBM Cloudant as the documentation directly relates to their product and it is a lot easier to follow.