Suppose I have two indexes in elasticsearch. First names contains five values Ram, Shyam, Hari, Dipu, Kishan and second profession contains five values like teacher, driver, doctor, bank manager, salesman. When someone types Ra, I want to show suggestions like
Ram is teacher
Ram is driver
Ram is doctor
Ram is bank manager
Ram is salesman
Similarly when someone types Har, I want to show
Hari is teacher
Hari is driver
Hari is doctor
Hari is bank manager
Hari is salesman
I don't want to store every possible combination.
Also suppose user is looking for Ram is a doctor at Raman Hospital since 2002. Here Ram, doctor, Raman Hospital, 2002 belongs to different-different indexes. When user types Ram I want to show suggestions as Ram is a teacher at Basic Boys School Since 2002, Ram is salesman at HUL since 2006. And if there is one more guy with name Raman then Raman is driver at Ola since 2012 should also be shown as suggestion. For such searches is there any good approach available or I have to work on that?
Mapping:
PUT name
{
"mappings": {
"_doc" : {
"properties" : {
"suggest" : {
"type" : "completion",
"contexts": [
{
"name": "userid",
"type": "category"
}
]
}
}
}
}
}
Indexing:
POST name/_doc/
{
"suggest": {
"input": ["BHANU PRAKASH"],
"contexts": {
"userid": ["99569858","99156661","90273758","6598242461","65910563"]
}
}
}
Related
I have the following JSON data.
{
"partners": [
{
"logo": "school-of-bookkeeping.png",
"title": "Schoolofbook<br class='d-none d-md-inline-block'/>keeping.com",
"websiteURL":"https://www.schoolofbookkeeping.com",
"getInTouchURL":"https://www.schoolofbookkeeping.com",
"location":"Santa Monical, CA, US",
"servicesCategories":["Consulting Services","Webgility Setup"],
"accountingSoftware":["QuickBooks Online","QuickBooks Enterprise","QuickBooks Point of Sale"],
"onlineStore":["Magento","Shopify","WooCommerce"],
"marketplace":["Amazon","eBay","Etsy"],
"description": "Teaching Businesses and Accounting Professionals the ins and outs of ecommerce.",
"longDescription":"<p class='fs-16 lh-1-5'>Let's face it; ecommerce is hard. From tracking inventory, sales tax requirements, shipping fulfillment, and general bookkeeping, keeping pace with all the requirements and business workflows is difficult. That's why we have partnered with Webgility to create a learning resource to provide small and medium-sized businesses a seamless and path from setup to implementation, so the accounting is done so that can focus on running your business, rather than your business, rather than running yourself ragged.</p><p class='fs-16 lh-1-5'>Our lifelong learners are here for hire so you can be set up for success and have a trusted advisor to guide you through setup to implementation.</p>",
"servicesWeProvide": "<p class='fs-16 lh-1-5'>Website creation to e-commerce implementation.</p>",
"featured": false,
"partnerType": "Certified",
"link": "school-of-bookkeeping",
"customClass": "school-of-bookkeeping"
},
{
"logo": "danwidth.png",
"title": "Danwidth",
"websiteURL":"https://www.danwidth.com",
"getInTouchURL":"https://completebusinessgroup.com/danwidth/",
"location":"Tucson, AZ, US",
"servicesCategories":["Consulting Services","Webgility Setup"],
"accountingSoftware":["QuickBooks Online","QuickBooks Enterprise","QuickBooks Point of Sale"],
"onlineStore":["Magento","Shopify","WooCommerce"],
"marketplace":["Amazon","eBay","Etsy"],
"description": "Put your ecommerce bookkeeping on cruise control.",
"longDescription":"<p class='fs-16 lh-1-5'>I don't want to be your bookkeeper. I transform businesses through technology by creating automagic workflows that allow your bookkeeping to be handled \"by accident.\" Imagine entering data once, or not at all, and your bookkeeping is done for you. Specializing in brick and mortar retail and ecommerce, I will set up your services to integrate so that your accounting and bookkeeping is done for you as a result of you simply running your business. We work with a host of solution providers that all integrate into your accounting platform that will enable you to make informed business decisions in real-time.</p><p class='fs-16 lh-1-5'>My expertise is unparalleled across all of Intuit's Small business platforms. Online or Desktop, including Point of Sale, if it can be done in QuickBooks, I know how to make it happen. In addition, we partner with other business services to increase your revenue, decrease your expenses, and widen your online presence.</p>",
"servicesWeProvide": "<p class='fs-16 lh-1-5'>End-to-end services from website creation, digital marketing, ecommerce platform to bookkeeping, payroll service setup, and support.</p>",
"featured": false,
"partnerType": "Certified",
"link": "danwidth",
"customClass": ""
}
]
}
How can I filter this on the basis of servicesCategories, accountingSoftware, onlineStore, marketplace, and partnerType?
I want to filter data with $.getJSON() method with on change select box value.
That depends on how you want to go about filtering. There are a few different ways to accomplish this, here is one function that allows you to pass in the key you want to filter on and an array of values to filter by:
let filterBy = (list, keyToFilter, filters) => {
// Allow a string to be passed in
if(!Array.isArray(filters)) filters = [filters];
return list.filter(item => {
let values = item[keyToFilter];
// Check if the filter exists
if(!values) return false;
// For items that aren't arrays, like partnerType
// This makes it compatible with the conditional
// below, where the logic for check happens.
if(!Array.isArray(values)) values = [values];
// Check if array of your filters matches any in list
return filters.some(n => values.includes(n));
}
);
};
Then you can call this on your list like so:
let list = { "partners": [
...
]};
let accountingSoftware = filterBy(list["partners"], "accountingSoftware", ["QuickBooks Online","QuickBooks Enterprise"]);
let partnerType = filterBy(list["partners"], "partnerType", "Certified");
Here is an example if you want to play around with it more, https://repl.it/#BenjaminKnox/filter-json
I am prototyping a Food Ordering app using Dialogflow(Chatbot maker) and got stuck with this problem. Technically, I want to persist the gathered data from an Intent after the user decided to "add more items to their order" and satisfies all the required parameters, which are, (itemName, quantity, [variants], [sauceType], ...).
The chat bot should be able to handle a request which consist of multiple items with their corresponding quantities but I am not sure if it's possible to model a data wherein it consist an array of Entities so, my first thought was to use a persistent Fulfillment using session-based Webhook with our custom Web Service, like for example: foodorder/api/order/123/items/add and 123 being the Session Id. But this approach requires more work and the generated model can be difficult to translate in Dialoflow Console.
The second solution comes into my mind, is to leverage the Intent property called Action and Parameters where we mark the Entity as List, but using this approach, the quantity doesn't get attached to the item itself.
My question is, how can I be able to model a data using Dialogflow that resembles something like below:
{
"givenName": "Dummy User",
"order": [
{
"itemName": "Burger",
"quantity": 2
},
{
"itemName": "6 piece Chicken Nuggets",
"quantity": 1,
"sauceType": "Tangy Barbeque"
},
{
"itemName": "Coke",
"quantity": 1,
"size": "Small"
}
]
}
Turns out what I was looking for was Composite Entities and mark it as a list.
The detailed answer can be found on this link:
https://stackoverflow.com/a/47166123/2304737
Which operator to use to push a new question into array of question?I have got the document in following format.Which mongo db operator to use to insert a new question into array of questions provided that i am given chapterId and subchapterId in advance.
For example i want to insert a new question in subchapterId "1".
{
"chapterId": "38",
"subChapter": [
{
"subchapterId": "1",
"questions": [
{
"title": "Either his however modern. Stop central owner color type out. Interview five beyond interesting type suddenly.",
},
{
"title": "Amount himself foreign color moment gun together sit. Deal race range heart despite several. Rather activity eat dinner save mission western. Civil past public enter four then.",
},
{
"title": "Four former operation. Class continue away treatment.\nResponsibility condition dinner realize everything. Sign scene order quality yet. Within sing statement skill popular southern whole."
},
{
"title": "Where of coach nature ask page allow.\nType exist hotel time. Central site policy everyone safe. Official administration family somebody.",
},
{
"title": "Necessary dark these much region. Form sometimes seek. Future according detail piece section.\nNear everything admit. Senior Republican draw as expert market.",
}
]
},
{
"subchapterId": "2",
"questions": [
{
"title": "Audience still use group. Yourself building police. Play imagine serious reality population reach.\nHerself without member must think concern window finish."
},
{
"title": "Rule trip manage still. Imagine religious above race something successful.\nOnce base American series. Low page quite allow. Customer maybe base leave way under blood.",
},
{
"title": "Church audience anyone garden. Federal when individual style.Value billion morning need box whether. Coach traditional cold each us truth.",
}
]
}
]
}
You can try this
const title = "this is the new question"
db.collection.update(
{ "subChapter.subchapterId": "1" },
{ "$push": { "subChapter.$.questions": { title } }}
)
You can use $push along with update
Example code is for chapterId:38 and subchapterId:1
db.collection_name.update({ "chapterId":"38", "subChapter.subchapterId": "1" }, { $push: { "subChapter.$.questions":{'title':'Newly added record'} }})
use $addToSet Which avoids the Duplicates in the Array of objects while updating
db.yourcollectionName.update({
"subChapter.subchapterId" :"1"
},{$addToSet:{"subChapter.$.questions":{title:"updated Object"}}})
I'm taking my first dive into noSQL (AWS DynamoDB) and writing a nodejs app which will maintain a product catalog. The product catalog has 2 types of item - Product and Category.
Products can appear in multiple categories. I'm really struggling to find a source of information on how best to approach this, I think using a query would be the right solution but ideally both the solution and the data would be elegant.
At present my products look a bit like:
{
"productId": 12930,
"productCode": "DIHA",
"name": "6 Bottle Beer Pack",
"onSale": true,
"newItem": false,
"relatedItems": [1240, 1201, 4508, 55067],
"categoryIds": [1201, 1202, 1203, 1204]
}
The aim is to be able to query products in a category e.g. 1203 and then filter by facets such as onSale & newItem.
I have seen an example whereby they flatten the categories like so
"category_1": 1201,
"category_2": 1202,
"category_3": 1203,
"category_4": 1204,
...
But something about that approach doesn't sit right with me (inelegant?)
I have played with using normalized tables e.g. CategoryProduct which lists the categoryIds with their related productIds.
{
1201: [12930, 12931, 12932, 12933 ...],
1202: [12930, 12678, 12679, 12680 ...],
1203: [12930, 12500, 12501],
1204: [12930, 12931],
...
}
But if my understanding is right then this would be quite resource heavy and lead to multiple reads just to acquire the products to filter against
Does anyone know of any tutorials or resources where filtering an entire catalog by categories or tags exists? I feel like I've trawled Google/GitHub/stackoverflow and not yet seen an example to go on.
I'll be eternally grateful if someone could share their knowledge/resources with me.
I know that if I simply try to get a list of my friends, it will only return app friends AKA friends who also have given permissions to Facebook
So, rightfully so, when I do a GET 'me/friends', I only see 5 friends.
However, when I do a GET me/posts/?fields=likes.fields(name), it obviously returns data with a list of friends who have liked my posts:
{
"id": "post1id",
"likes": {
"data": [
{
"name": "name1",
"id": "id1"
},
{
"name": "name2",
"id": "id2"
}....
]
}
It shows all friends, so non-app and app friends.
My question is, if all I want to use is my friends' names and id's from this result, would it be allowed, considering that some of these friends are not app-friends?
If you work the API with the user token, you may receive all likes (including friends who don't use the app, non-friends, friends who use the app, pages) but this is at all no indication for a users friends. Anyways you can utilize ALL data provided by the GraphAPI as long as you don't work around the limitations with something like exploiting the game invite feature.