Example: Search for Profiles with an Email Address

Retrieve up to 5 profiles with an email address in the database. This query checks for the existence of the profile_info.emails field.

{
  "query": {
    "exists": {
      "field": "profile_info.emails"
    }
  },
  "limit": 5
}

Example: Search for Data Science Professionals

Search for 10 people working in data science. Using match query we perform a full text search, meaning that we may get people who currently work as data scientists or in a similar position.

{
  "query": {
    "match": {
      "profile_info.current_title": {
        "query": "data scientist",
        "operator": "AND"
      }
    }
  },
  "limit": 10
}

Thanks to mapping profile_info.current_title as both text and keyword (See OpenSearch Mapping), we can easily perform an exact search on this field. Below we search for people whose role is titled “Data Scientist”. Mind that we use term query to perform the search.

{
  "query": {
    "term": {
      "profile_info.current_title.raw": {
        "value": "Data Scientist"
      }
    }
  },
  "limit": 10
} 

Combine Multiple Search Conditions

To perform a search based on multiple conditions, we need to use a boolean query. We want all the conditions to be met, so must clause is the proper one. The below query will return all Software Developers working at The Swarm company. For other logical operation refer to OpenSearch documentation.

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "profile_info.current_title": {
              "query": "software developer"
            }
          }
        },
        {
          "match": {
            "profile_info.current_company_name.raw": {
              "query": "The Swarm"
            }
          }
        }
      ]
    }
  }
} 

Search for Recently Updated Profiles

Retrieve profiles in the Information Technology and Services industry that had their current job updated within a specific date range. This query uses a combination of range and term filters.

{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "profile_info.current_job_updated_at": {
              "gte": "2024-05-12",
              "lte": "2024-05-18"
            }
          }
        },
        {
          "term": {
            "profile_info.current_company_industry": {
              "value": "Information Technology and Services"
            }
          }
        }
      ]
    }
  }
}

Search by Location and Past Experience

Retrieve profiles of people located in the United States who previously held a product-related role at Google. This query uses a nested query to access past experiences and excludes current roles with the must_not clause.

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "profile_info.location_country": {
              "value": "united states"
            }
          }
        },
        {
          "nested": {
            "path": "profile_info.experience",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "profile_info.experience.company.name": {
                        "query": "Google"
                      }
                    }
                  },
                  {
                    "match": {
                      "profile_info.experience.title.name": {
                        "query": "Product"
                      }
                    }
                  },
                  {
                    "bool": {
                      "must_not": [
                        {
                          "exists": {
                            "field": "profile_info.experience.is_current"
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}