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,
  }
}
@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