Search

Last edit: Jun 11, 2019
  • Contributors:
  • pavelloz

In platformOS, we support searching and filtering using Elasticsearch.

Search is usually more complex than other GraphQL queries because of the many additional filters that you can choose from. You can build search for any object supported in GraphQL.

Elasticsearch indexes

The following GraphQL entry points are powered by the Elasticsearch index:

  • Customizations
  • Listings
  • People

Each model property has two corresponding fields in the Elasticsearch index:

  • The first field gets analyzed (tokenized) during document creation/update, and might be different than the origin.
  • The second field is unchanged (.raw).

Examples:

raw tokenized
www.platform-os.com www.platform os.com
darek@near-me.com darek near me.com
word.other,another word other another
`word other

The raw field data is used mostly for both exact filtering and sorting while the analyzed field is used for full text searching (query).

In most cases, you don't have to specify which field to use - it's automated and based on operation type. But you can explicitly point out which field to be used by appending the .raw postfix to the field name:

{
  customizations(
    query: {
      keyword: "example"
      fields: [
        { name: "properties.title.raw", priority: 1 }
      ]
    }
  ){
    results {
      title: property(name: "title")
    }
  }
}

Keyword search

By default keyword search is looking in all fields that are provided to the database. Use query if you want to do a full-text search for a keyword. It does a full-text search across all analyzed (tokenized) fields.

In your GraphQL query, you can narrow the field list by adding parameter fields.

If you leave the keyword field empty, it means you are looking for everything, so narrowing by field names will not be applied.

Learn more about narrowing keyword search in our Narrowing Keyword Search topic.

Example:

{
  customizations(
    query: {
      keyword: "example"
      fields: [
        { name: "properties.summary", priority: 1 }
        { name: "properties.bio", priority: 3 }
      ]
    }
  ){
    results {
      name
      summary: property(name: "summary")
      bio: property(name: "bio")
    }
  }
}

Keyword match type

Search by default tries to match the keyword exactly with the words in the field. When you search for alan it will match values alan but also Mike Alan and Mike Alan and Tommy. You can also define keyword to match words that start or end with the specified phrase.

Learn more about keyword match type in our Keyword Match Type topic.

Related topics

Questions?

We are always happy to help with any questions you may have.