Dec 25th, 2020 [EN] Santa’s Little Helper - Workplace Search

Santa’s Little Helper - Workplace Search

You might have picked up on this from movies: Santa’s operation is pretty high tech.

It’s a big job, coordinating a massive workforce of Elves to ensure the timely delivery of billions of presents each year. This year, Santa is particularly excited to make use of Elastic’s Workplace Search for its first Christmas.

You see, Santa and his team are working with a lot of data:

  • Children all over the world are sending him letters and emails to let him know what their wish lists are.
  • He’s got R&D designing and perfecting thousands of new toys each year.
  • The assembly line teams require precise numbers to ensure that the right quantity of each toy gets produced.
  • His fulfillment team has a mad scramble at the end to ensure that every single child gets the specific toy they wanted.
  • The support desk has to field enormous request volumes on these new toys,
    • From parents before the holiday (“Does this toy come with batteries included?”)
    • From children afterwards (“Are there any cheat codes?”).

In years previous, this meant Santa had to hold a lot in his head - remembering how to log in to each of these separate data stores, how to search in them, and how to find the right subject-matter-experts for any given problem. But not this year!

For 2020, Santa created an Elastic Cloud deployment for Enterprise Search.

Then he followed the simple instructions to connect the corporate accounts for Google Drive (Toy R&D designs and plans), Jira (Manufacturing - North Pole: East), Github (Manufacturing - North Pole: West), and Zendesk (Customer Support).

He’s also got IT to develop a Custom API Source that indexes every wishlist item.

So now, it’s super simple to keep tabs on all the phases of development for his operation.

But Santa’s most excited about an early Christmas present that the folks at Elastic gave him - the latest Enterprise Search Clients. At the start of November, Santa took a bit of PTO before the “busy season.” When he got back, it was to find that he'd forgotten to set up mail-forwarding, and he had a huge backlog of wish-list letters from kids! But with the Enterprise Search Ruby Client, Santa knew he could get caught up in no-time.

First, he had to get his Search Access Token, by going through a simple OAuth flow.

With that Access Token, he could then instantiate his Ruby Client.

require 'elastic/enterprise_search'
host = 'http://localhost:3002'
access_token = 'e7ec70860d426ce42c6d6d7448abb5b21f8292e3ecda3636ef6757bc320e7fea'
ent_client = Elastic::EnterpriseSearch::Client.new(:host => host)
ent_client.workplace_search.http_auth = access_token

Next, he had to identify what he’d missed while he was out. An easy range filter since his start date PTO would do, combined with a value filter for his Wish List Content Source.

pto_start_date = '2020-11-05T00:00:00Z'
wish_list_content_source_id = '5fd1490d4993c8a47f1af495'
recent_wish_list_items = ent_client.workplace_search.search(
  :body =>  {
    :filters => {
      :all => [
        {
          :content_source_id => [wish_list_content_source_id]
        },
        {
          :last_updated => {
            :from => pto_start_date
          }
        }
      ]
    }
  }
).body

There were a LOT of results. But that’s ok, Santa knew that paging through them wouldn’t be an issue.

irb(main):122:0> puts JSON.pretty_generate(recent_wish_list_items['meta'])
{
  "page": {
    "current": 1,
    "total_pages": 1893620,
    "total_results": 18936198,
    "size": 10
  },
  "request_id": "6ddba763-3cdf-4ecb-bd78-92faed3f9ea4",
  "warnings": [

  ]
}
=> nil
irb(main):123:0>

The next step was to make sure that each child’s request had already been filed as a Github Issue or Jira Story. Which system it would be tracked under depends on which team had picked up the child’s request, so an any filter would be called for, along with a value filter for the child’s name, and a query for the desired toy.

Finally, since the child might have requested something similar in the past, Santa added a recency boost to ensure that recent wish list items got higher precedence.

github_content_source_id = '5fd149914993c845738928f7'
jira_content_source_id = '5fd149a34993c81691892918'
missing_assignee = []
missing_issue = []
recent_wish_list_items['results'].each do |wish_list_item|
  search_params = {
    :body =>  {
      :filters => {
        :any => [
          {
            :content_source_id => [github_content_source_id]
          },
          {
            :content_source_id => [jira_content_source_id]
          }
        ],
        :all => [
          {
            :title => [wish_list_item['child']['raw']]
          }
        ]
      },
      :query => wish_list_item['toy']['raw'],
      :boosts => {
        :recency => {
          :type => 'proximity',
          :function => 'exponential',
          :center => 'now'
        }
      }
    }
  }
  issues_matching_childs_wish = ent_client.workplace_search.search(search_params).body['results']
  if issues_matching_childs_wish.empty?
    missing_issue << wish_list_item
  elsif issues_matching_childs_wish[0]['assigned_to']&.fetch('raw').nil?
    missing_assignee << issues_matching_childs_wish[0]
  end
end

puts "#{missing_assignee.map { |issue| issue['url']['raw'] }} are missing assignees" unless missing_assignee.empty?
puts "#{missing_issue.map { |item| item['child']['raw'] }} are missing issues" unless missing_issue.empty?

If there was a good match with an assignee, Santa could check this one off his list. But if not, he marked the link to follow-up on - just to make sure no child slipped through the cracks.
But for some children/items, there wasn’t a corresponding issue/story yet.

["https://github.santa.com/xmas2020/issues/99383", "https://north-pole.atlassian.net/browse/C2-13829634"] are missing assignees
["Sally Sitwell", "Patty Labadie"] are missing issues

For these, Santa would need to find the subject matter expert for the particular toy, and get their guidance on who should follow up. Santa knew that the best experts would be the Elf Architects who had created the original designs for the toys.

Another value filter to limit to just the Google Drive source, a query for the toy, and limiting the result field to just the author of the document got him his experts right away.

google_drive_content_source_id = '5fd149b84993c8345b892996'
missing_issue.each do |wish_list_item|
  toy = wish_list_item['toy']['raw']
  search_params = {
    :filters => {
      :content_source_id => [google_drive_content_source_id]
    },
    :result_fields => {
      :author => {
        :raw => {}
      }
    },
    :query => toy
  }
  designs_matching_childs_wish = ent_client.workplace_search.search(search_params).body['results']
  authors = designs_matching_childs_wish.map { |design| design['author']['raw'] }
  puts "Subject matter experts for '#{toy}' are: #{authors}"
end
Subject matter experts for 'Balance Beam' are: ["Evan Gilmore", "Rahim Bhayani"]
Subject matter experts for 'Soccer ball' are: ["Patrick Rengardt"]

And with that, Santa was able to lean back, drink some cocoa, and feel confident that he and his team would hit their all-important deadline. Rudolph may be leading the sleigh, but this year, Elastic Workplace Search is making Santa’s enterprise fly.

2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.