Skip to content

Instantly share code, notes, and snippets.

@RohitRox
Last active May 30, 2019 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RohitRox/63e89cf2658974e11f7fbfa89b174699 to your computer and use it in GitHub Desktop.
Save RohitRox/63e89cf2658974e11f7fbfa89b174699 to your computer and use it in GitHub Desktop.
ES-User-Search

ES Document Struct

{
  "_index": "users_index",
  "_type": "_doc",
  "_id": "iam-id-uuid",
  "_score": 1,
  "_source": {
    "iam_id": "iam-id-uuid",
    "role_id": "c65e502d-39b2-46cb-850e-73a32eaf9364",
    "email": "mohamed.gusikowski@cloudfactory.com",
     "ucid": "01e2506b-d8b8-4c30-9346-bc4b2fa319f2",
     "first_name": "Mohamed",
     "last_name": "Gusikowski",
     "full_name": "Mohamed Gusikowski",
     "countries": [
       "Nepal",
       "Kenya"
     ],
  }
}

Custom Attribute Metadata Schema (Constant for now, will be used in FE and BE)

{
 searchable: [
    full_name,
    email,
 ],
 filterable: [
    role_id,
    countries
 ],
 sortable: [
   full_name,
   email
 ],
 viewable: [
    full_name,
    email,
    role_id
 ],
 meta: {
  first_name: {
    type: 'text',
    label: "First Name"
  },
  last_name: {
    type: 'text',
    label: "Last Name"
  },
  full_name: {
    type: 'text',
    label: "Name"
  },
  email: {
    type: 'text',
    label: "Email"
  },
  role_id: {
    type: 'list',
    options: [ {value: 'xxx', label: 'Cloud Worker'}, {value: 'nnn', label: 'Employee'} ],
    label: "Role"
  },
  countries: {
   type: 'list',
   options: [ {value: 'Nepal', label: 'Nepal'}, {value: 'Kenya', label: 'Kenya'} ],
   label: 'country'
  }
}

BE Api

// also illustrate order of preference
/use/search/api/users?filter[countries][]=nepal&filter[countries][]=kenya&filter[full_name]=test
/use/search/api/users?q=
/use/search/api/users?sort_by=field&sort_order=asc
/use/search/api/users?page=1&per_page=20
{
  entries: [{
    iam_id: 'xxx',
    role_id: 'xxx-xxx',
    ucid: 'xxx-xxx',
    first_name: 'David',
    last_name: 'Costa',
    full_name: 'David Costa'
    email: 'd@cf.com',
    countries: ['Kenya'],
  }],
  metadata: {
    total: 100,
    page: 1,
    per_page: 50,
  }
}
@RohitRox
Copy link
Author

Would one worker be associated with multiple countries? As in the example multiple countries are returned.
Since in the UI we are merging first_name and last_name fields and applying string trucation in email field we would create an UI assuming the fields first_name, last_name and email are always present and others can be dynamically added but would require a label field for the title in the table. Here thus role_id should also have a label associated with it.

A/C to custom attributes, YES, one user can be assigned in multiple countries.
In custom attributes, it's an array, so API will also return an array.
Regarding first_name and last_name, I also don't have an answer, cause our current custom attribute data architecture does not yet support this use-case. Custom attribute won;t be able to tell us, use Name field which is a combination of first_name and last_name. For now, we'll have to so something in the UI to join first_name and last_name and show it as a Name field. Long term solution would be, custom attribute will store info about this field and how to compute value of this field.

For sorting, I was thinking if UI could pass sort=first_name+last_name, both, the api could can do a sort by combination of two fields against ES.

@gaurab13
Copy link

In Custom Attribute Metadata Schema, we probably need to settle on a specific format on how options for list type attributes inside meta are returned as. In role attribute, options is returned as [ {id: 'xxx', name: 'Cloud Worker'}, {id: 'nnn', name: 'Employee'} ] which is understandable and needed. But for any other list type fields like countries just having an array of strings will create problems in the UI.

Our Select component currently accepts an array of this format [ label: 'Nepal', value: 'Nepal'], where label is whats shown in the UI.
For the UI all list type fields will behave the same, so having a proper format will make it easy for the front end to manipulate and use it.
So can we send the country options as [ {id: 'nepal', name: 'Nepal'}, {id: 'kenya', name: 'Kenya'} ] ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment