Type to search.

Result

Serverless

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Serverless interfaces and procedures might differ from classic Elastic Stack deployments.

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

Displays a search result.

Jsx
import { Result } from "@elastic/react-search-ui";

...

<SearchProvider config={config}>
  {({ results }) => {
    return (
      <div>
        {results.map(result => (
          <Result key={result.id.raw}
            result={result}
            titleField="title"
            urlField="nps_link"
          />
        ))}
      </div>
    );
  }}
</SearchProvider>

Certain aspects of search results can be configured in SearchProvider, using the searchQuery configuration, such as term highlighting and search fields. See the Search Query Configuration guide for more information.

Name Description
className
titleField Name of field to use as the title from each result.
shouldTrackClickThrough Whether or not to track a clickthrough event when clicked.
clickThroughTags Tags to send to analytics API when tracking clickthrough.
urlField Name of field to use as the href from each result.
result Type: SearchResult. An object representing the search result to render.
view Used to override the default view for this Component. See View customization below.
* Any other property passed will be passed through and available to use in a Custom View

A complete guide to view customization can be found in the Customization: Component views and HTML section.

Example:

Jsx
const CustomResultView = ({
  result,
  onClickLink
}: {
  result: SearchResult,
  onClickLink: () => void
}) => (
  <li className="sui-result">
    <div className="sui-result__header">
      <h3>
        {/* Maintain onClickLink to correct track click throughs for analytics*/}
        <a onClick={onClickLink} href={result.nps_link.raw}>
          {result.title.snippet}
        </a>
      </h3>
    </div>
    <div className="sui-result__body">
      {/* use 'raw' values of fields to access values without snippets */}
      <div className="sui-result__image">
        <img src={result.image_url.raw} alt="" />
      </div>
      {/* Use the 'snippet' property of fields with dangerouslySetInnerHtml to render snippets */}
      <div
        className="sui-result__details"
        dangerouslySetInnerHTML={{ __html: result.description.snippet }}
      ></div>
    </div>
  </li>
);

<Results resultView={CustomResultView} />;

The following properties are available in the view:

Name Description
className Passed through from main component.
result Type: SearchResult. An object representing the search result to render.
onClickLink function() - Call this when a link is clicked to trigger click tracking. Only triggered if shouldTrackClickThrough was set to true on the main component.
titleField Passed through from main component. Not usually needed for custom views.
urlField Passed through from main component. Not usually needed for custom views.
thumbnailField Passed through from main component. Not usually needed for custom views.

See Result.tsx for an example.