Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Using the Search node, you can query against the data and retrieve the results that match the specified criteria. Refer, Search node

Example

Create a schema named facilitydataschema. Every document (facility) created with this schema contains the fields (information) such as facility name, facility image, address, phone number, location (latitude and longitude), etc.

Sample schema (facilitydata) used in this example is:

Code Block
{
    "fields": [
        {
            "type": "String",
            "fieldType": "text",
            "ref": "",
            "options": [],
            "multiple": false,
            "validation": [
                {
                    "required": false
                }
            ],
            "isDefault": false,
            "label": "Hospital Name",
            "key": "hospitalname"
        },
        {
            "type": "String",
            "fieldType": "text",
            "ref": "",
            "options": [],
            "multiple": false,
            "validation": [
                {
                    "required": false
                }
            ],
            "isDefault": false,
            "label": "City",
            "key": "city"
        },
        {
            "type": "Object",
            "fieldType": "json",
            "ref": "",
            "options": [],
            "multiple": false,
            "validation": [
                {
                    "required": true
                }
            ],
            "isDefault": false,
            "label": "Location Object",
            "key": "location",
            "es": "geo_point"
        }
    ]
}

You can query for any of these fields and get the document and render the information to the clientchatbot.
For example, if you wanted to know all the hospitals that are available in Davenport city, you can query for the city name and get the results.

The sample document with the above schema is shown below.

...

In the Experience Designer, construct a flow as shown.

...

Place the below code in the City name search function node:

Code Block
queriedCity = msg.payload.request.intent.slots.city_slot.value
msg.payload.q = {
    "query": {
      "bool": {
        "must": {
          "match": {
            "city": queriedCity
          }
        }
      }
    }
  }
return msg;

The Search node configuration is as follows:

...

Code Block
{
    "q" : "{{msg.payload.q}}"
}

Place the below code in the Hospital Names function node:

Code Block
hospitalNameList = "";

hospitalName = msg.payload.search.hits.hits;
node.warn(hospitalName);

var i;
for (i = 0; i < hospitalName.length; i++) {
  hospitalNameList += hospitalName[i]._source.hospitalname + ", ";
}

msg.payload.hospitalNameList = hospitalNameList;
return msg;

The say node configuration is as follows:

...

Export file for the Experience Designer flow:

Attachments
previewfalse
uploadfalse
oldfalse
patterns.*json

In the chatbot, if the chatbot user says Davenport, the Search node will get the hospital names that have the city field as Davenport.

...