PHPackages                             flowpack/elasticsearch-contentrepositoryadaptor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. flowpack/elasticsearch-contentrepositoryadaptor

ActiveNeos-package[Search &amp; Filtering](/categories/search)

flowpack/elasticsearch-contentrepositoryadaptor
===============================================

This package provides functionality for using Elasticsearch on top of Neos.ContentRepository.Search

9.0.3(6mo ago)43385.8k↓19.8%72[9 PRs](https://github.com/Flowpack/Flowpack.ElasticSearch.ContentRepositoryAdaptor/pulls)8LGPL-3.0-onlyPHPPHP ^8.2

Since May 26Pushed 3mo ago10 watchersCompare

[ Source](https://github.com/Flowpack/Flowpack.ElasticSearch.ContentRepositoryAdaptor)[ Packagist](https://packagist.org/packages/flowpack/elasticsearch-contentrepositoryadaptor)[ Docs](http://flowpack.org/)[ RSS](/packages/flowpack-elasticsearch-contentrepositoryadaptor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (90)Used By (8)

[![Build Status](https://camo.githubusercontent.com/d56e9cf19eee05f3b47cd5763bc22a02da8d78bb8b1ee2d55ed800fafc4ccebd/68747470733a2f2f7472617669732d63692e636f6d2f466c6f777061636b2f466c6f777061636b2e456c61737469635365617263682e436f6e74656e745265706f7369746f727941646170746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/Flowpack/Flowpack.ElasticSearch.ContentRepositoryAdaptor) [![Latest Stable Version](https://camo.githubusercontent.com/ba80074d3b0cca4f87d07b832b285c832e8a8d158c1a3e392c570d1797952370/68747470733a2f2f706f7365722e707567782e6f72672f666c6f777061636b2f656c61737469637365617263682d636f6e74656e747265706f7369746f727961646170746f722f762f737461626c65)](https://packagist.org/packages/flowpack/elasticsearch-contentrepositoryadaptor) [![Total Downloads](https://camo.githubusercontent.com/c6a76d519c72b492ea3027ce9a8c30237da1f95b083cbb66097c3873f7fc951b/68747470733a2f2f706f7365722e707567782e6f72672f666c6f777061636b2f656c61737469637365617263682d636f6e74656e747265706f7369746f727961646170746f722f646f776e6c6f616473)](https://packagist.org/packages/flowpack/elasticsearch-contentrepositoryadaptor)

Neos Elasticsearch Adapter
==========================

[](#neos-elasticsearch-adapter)

This project connects the Neos Content Repository to Elasticsearch; enabling two main functionalities:

- finding Nodes in Fusion / Eel by arbitrary queries
- Full-Text Indexing of Pages and other Documents (of course including the full content)

This documentation is structured in the following parts:

- [Installation](#installation): Which packages are needed and how they are installed.
- [Commands](#commands): This section describes the available ./flow CLI commands
- [Configuration](#configuration): Configuration of indices, fields, ...
- [Query Data](#query-data): Available Eel operations to query data
- [Examples](#examples): Some more advanced examples

Installation
============

[](#installation)

```
composer require 'flowpack/elasticsearch-contentrepositoryadaptor'
// Not required, but can be used to learn how to integration the flowpack/elasticsearch-contentrepositoryadaptor in your project
composer require 'flowpack/searchplugin'

```

Ensure to update `/config/elasticsearch.yml` as explained below; then start Elasticsearch.

Finally, run `./flow nodeindex:build`, and add the search plugin to your page. It should "just work".

Relevant Packages
-----------------

[](#relevant-packages)

- [Neos.ContentRepository.Search](https://www.neos.io/download-and-extend/packages/neos/neos-content-repository-search.html): provides common functionality for searching Neos Content Repository nodes. Does not contain a search backend.
- [Flowpack.ElasticSearch](https://www.neos.io/download-and-extend/packages/flowpack/flowpack-elasticsearch.html): provides common code for working with Elasticsearch
- [Flowpack.ElasticSearch.ContentRepositoryAdaptor](https://www.neos.io/download-and-extend/packages/flowpack/flowpack-elasticsearch-contentrepositoryadaptor.html): this package
- [Flowpack.SimpleSearch.ContentRepositoryAdaptor](https://www.neos.io/download-and-extend/packages/flowpack/flowpack-simplesearch-contentrepositoryadaptor.html): an alternative search backend (to be used instead of this package); storing the search index in SQLite
- [Flowpack.SearchPlugin](https://www.neos.io/download-and-extend/packages/flowpack/flowpack-searchplugin.html): search plugin for Neos

Elasticsearch and Neos compatibility
------------------------------------

[](#elasticsearch-and-neos-compatibility)

This following matrix shows the compatibility of this package to Elasticsearch and Neos versions:

CR AdaptorNeosElasticsearchStatus43.x, 4.x1.x, 2,x 5.xUnmaintained, probably broken5&gt; 3.3, 4.x5.xUnmaintained65.x5.xUnmaintained75.x6.x, 7.xUnmaintained87.x, 8.x6.x, 7.x, 8.xBugfix and Features99.x6.x, 7.x, 8.xBugfix and Features ([Upgrade Instructions](Documentation/Upgrade-8-to-9.md))*Currently the Driver interfaces are not marked as API, and can be changed to adapt to future needs.*

### Elasticsearch Configuration file elasticsearch.yml

[](#elasticsearch-configuration-file-elasticsearchyml)

The following general configuration advice can make your life easier:

```
# the following settings secure your cluster
cluster.name: [PUT_YOUR_CUSTOM_NAME_HERE]
node.name: [PUT_YOUR_CUSTOM_NAME_HERE]
network.host: _local_
```

There may be a need, to add specific configuration to your Elasticsearch Configuration File `/config/elasticsearch.yml`, depending on your version of Elasticsearch.

- [Elasticsearch 5.x](Documentation/ElasticConfiguration-5.x.md)

Commands
========

[](#commands)

All commands are operating on a single content repository. If you don't specify the content repository identifer by `--contentRepository` the `default` content repository is used.

### Building up the index

[](#building-up-the-index)

The node index is updated on the fly, but during development you need to update it frequently.

In case of a mapping update, you need to reindex all nodes. Don't worry to do that in production; the system transparently creates a new index, fills it completely, and when everything worked, changes the index alias.

```
./flow nodeindex:build

```

if during development, you only want to index a few nodes, you can use "limit"

```
./flow nodeindex:build --limit 20

```

### Cleanup old indices

[](#cleanup-old-indices)

In order to remove old, non-used indices, you should use this command from time to time:

```
./flow nodeindex:cleanup

```

### Debug commands

[](#debug-commands)

The following commands are meant to be used for debugging while configuring and developing your search:

```
./flow nodeindexmapping:indices

```

Shows the mapping between the projects dimensions presets and the resulting index name.

```
./flow nodeindexmapping:mapping

```

Shows the mapping created for the NodeTypes.

```
./flow nodetype:showIndexableConfiguration

```

Shows a list of NodeTypes and if they are configured to be indexable

```
./flow search:viewnode  [] []

```

Shows all contents that are indexed fo a given node.

```
./flow search:fulltext

```

Performs a fulltext search and displays the results.

Configuration
=============

[](#configuration)

Index Settings
--------------

[](#index-settings)

If you want to fine-tune the indexing and mapping on a more detailed level, you can do so in the following way.

### Configure the index name

[](#configure-the-index-name)

If you need to run serveral (different) neos instances on the same elasticsearch server you will need to change the Configuration/Settings.yaml indexName for each of your project.

So `./flow nodeindex:build` or `./flow nodeindex:cleanup` won't overwrite your other sites index.

```
Neos:
  ContentRepository:
    Search:
      elasticSearch:
        indexName: useMoreSpecificIndexName
```

If you use multiple client configurations, please change the *default* key just below the *indexes*.

### Configure per index

[](#configure-per-index)

You can set one default configuration for all indices with your index prefix.

```
Flowpack:
  ElasticSearch:
    indexes:
      default: # Configuration bundle name
        neoscontentrepository: # The index prefix name, must be the same as in the Neos.ContentRepository.Search.elasticSearch.indexName setting
          settings:
            index:
              number_of_shards: 1
              number_of_replicas: 0
```

### Configure per dimension

[](#configure-per-dimension)

As an index is created for every dimension combination of the Neos content repository, you can configure the index behavior for every dimension combination separately.

**Caution: Default configuration and per dimension combination configuration is not merged. If a configuration for a dimension-combination is found, this configuration is used.**

```
Flowpack:
  ElasticSearch:
    indexes:
      default:
        'neoscontentrepository-0359ed5c416567b8bc2e5ade0f277b36': # The hash specifies the dimension combination
          settings:
            index:
              number_of_shards: 1
              number_of_replicas: 0
            analysis:
              filter:
                elision:
                  type: 'elision'
                  articles: [ 'l', 'm', 't', 'qu', 'n', 's', 'j', 'd' ]
              analyzer:
                custom_french_analyzer:
                  tokenizer: 'letter'
                  filter: [ 'asciifolding', 'lowercase', 'french_stem', 'elision', 'stop' ]
                tag_analyzer:
                  tokenizer: 'keyword'
                  filter: [ 'asciifolding', 'lowercase' ]
```

Which dimension combinations are available in your system and which hashes they are identified with can be shown with the CLI command:

```
./flow nodeindexmapping:indices

```

### Configurations per property (index field)

[](#configurations-per-property-index-field)

Then, you can change the analyzers on a per-field level; or e.g. reconfigure the \_all field with the following snippet in the NodeTypes.yaml. Generally this works by defining the global mapping at `[nodeType].search.elasticSearchMapping`:

```
'Neos.Neos:Node':
  search:
    elasticSearchMapping:
      myProperty:
        analyzer: custom_french_analyzer
```

Exclude NodeTypes from indexing
-------------------------------

[](#exclude-nodetypes-from-indexing)

By default the indexing processes all NodeTypes, but you can change this in your *Settings.yaml*:

```
Neos:
  ContentRepository:
    Search:
      defaultConfigurationPerNodeType:
        '*':
          indexed: true
        'Neos.Neos:FallbackNode':
          indexed: false
        'Neos.Neos:Shortcut':
          indexed: false
        'Neos.Neos:ContentCollection':
          indexed: false
```

You need to explicitly configure the individual NodeTypes (this feature does not check the Super Type configuration). But you can use a special notation to configure a full namespace, `Acme.AcmeCom:*` will be applied for all node types in the `Acme.AcmeCom` namespace. The most specific configuration is used in this order:

- NodeType name (`Neos.Neos:Shortcut`)
- Full namespace notation (`Neos.Neos:*`)
- Catch all (`*`)

Advanced Indexing configuration
-------------------------------

[](#advanced-indexing-configuration)

### Indexing configuration per data type

[](#indexing-configuration-per-data-type)

**The default configuration supports most use cases and often may not need to be touched, as this package comes with sane defaults for all Neos data types.**

Indexing of properties is configured at two places. The defaults per-data-type are configured inside `Neos.ContentRepository.Search.defaultConfigurationPerType` of `Settings.yaml`. Furthermore, this can be overridden using the `properties.[....].search` path inside `NodeTypes.yaml`.

This configuration contains two parts:

- Underneath `elasticSearchMapping`, the Elasticsearch property mapping can be defined.
- Underneath `indexing`, an Eel expression which processes the value before indexing has to be specified. It has access to the current `value` and the current `node`.

Example (from the default configuration):

```
 # Settings.yaml
Neos:
  ContentRepository:
    Search:
      defaultConfigurationPerType:

        # strings should just be indexed with their simple value.
        string:
          elasticSearchMapping:
            type: string
          indexing: '${value}'
```

### Indexing **configuration** per property

[](#indexing-configuration-per-property)

```
 # NodeTypes.yaml
'My.Package:NodeType':
  properties:
    'dateTime':
      search:

        # A date should be mapped differently, and in this case we want to use a date format which
        # Elasticsearch understands
        elasticSearchMapping:
          type: DateTime
          format: 'date_time_no_millis'
        indexing: '${(q(node).property("dateTime") ? Date.format(q(node).property("dateTime"), "Y-m-d\TH:i:sP") : null)}'
```

If your nodetypes schema defines custom properties of type DateTime, you have got to provide similar configuration for them as well in your `NodeTypes.yaml`, or else they will not be indexed correctly.

There are a few indexing helpers inside the `Indexing` namespace which are usable inside the `indexing` expression. In most cases, you don't need to touch this, but they were needed to build up the standard indexing configuration:

- `Indexing.buildAllPathPrefixes`: for a path such as `foo/bar/baz`, builds up a list of path prefixes, e.g. `['foo', 'foo/bar', 'foo/bar/baz']`.
- `Indexing.extractNodeTypeNamesAndSupertypes(Node)`: extracts a list of node type names for the passed node type and all of its supertypes
- `Indexing.convertArrayOfNodesToArrayOfNodeIdentifiers(array $nodes)`: convert the given nodes to their node identifiers.

#### Skip indexing and mapping of a property

[](#skip-indexing-and-mapping-of-a-property)

If you don't want a property to be indexed, set `indexing: false`. In this case no mapping is configured for this field. This can be used to also solve a type conflict of two node properties with same name and different type.

### Fulltext Indexing

[](#fulltext-indexing)

In order to enable fulltext indexing, every `Document` node must be configured as *fulltext root*. Thus, the following is configured in the default configuration:

```
'Neos.Neos:Document':
  search:
    fulltext:
      isRoot: true
```

A *fulltext root* contains all the *content* of its non-document children, such that when one searches inside these texts, the document itself is returned as result.

In order to specify how the fulltext of a property in a node should be extracted, this is configured in `NodeTypes.yaml` at `properties.[propertyName].search.fulltextExtractor`.

An example:

```
'Neos.Neos.NodeTypes:Text':
  properties:
    'text':
      search:
        fulltextExtractor: '${Indexing.extractHtmlTags(value)}'

'My.Blog:Post':
  properties:
    title:
      search:
        fulltextExtractor: '${Indexing.extractInto("h1", value)}'
```

### Working with Dates

[](#working-with-dates)

As a default, Elasticsearch indexes dates in the UTC Timezone. In order to have it index using the timezone currently configured in PHP, the configuration for any property in a node which represents a date should look like this:

```
'My.Blog:Post':
  properties:
    date:
      search:
        elasticSearchMapping:
          type: 'date'
          format: 'date_time_no_millis'
        indexing: '${(value ? Date.format(value, "Y-m-d\TH:i:sP") : null)}'
```

This is important so that Date- and Time-based searches work as expected, both when using formatted DateTime strings and when using relative DateTime calculations (eg.: `now`, `now+1d`).

If you want to filter items by date, e.g. to show items with date later than today, you can create a query like this:

```
${...greaterThan('date', Date.format(Date.Now(), "Y-m-d\TH:i:sP"))...}

```

For more information on Elasticsearch's Date Formats, [click here](http://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html).

### Working with Assets / Attachments

[](#working-with-assets--attachments)

If you want to index attachments, you need to install the [Elasticsearch Ingest-Attachment Plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest-attachment.html). Then, you can add the following to your `Settings.yaml`:

```
Neos:
  ContentRepository:
    Search:
      defaultConfigurationPerType:
        'Neos\Media\Domain\Model\Asset':
          elasticSearchMapping:
            type: text
          indexing: ${Indexing.extractAssetContent(value)}
```

or add the attachments content to a fulletxt field in your NodeType configuration:

```
  properties:
    file:
      type: 'Neos\Media\Domain\Model\Asset'
      ui:
      search:
        fulltextExtractor: ${Indexing.extractInto('text', Indexing.extractAssetContent(value))}
```

By default `Indexing.extractAssetContent(value)` returns the asset content. You can use the second parameter to return asset meta data. The field parameter can be set to one of the following: `content, title, name, author, keywords, date, content_type, content_length, language`.

With that, you can for example add the keywords of a file to a higher boosted field:

```
  properties:
    file:
      type: 'Neos\Media\Domain\Model\Asset'
      ui:
      search:
        fulltextExtractor: ${Indexing.extractInto('h2', Indexing.extractAssetContent(value, 'keywords'))}
```

Query Data
==========

[](#query-data)

We'll first show how to do arbitrary Elasticsearch Queries in Fusion. This is a more powerful alternative to FlowQuery. In the long run, we might be able to integrate this API back into FlowQuery, but for now it works well as-is.

Generally, Elasticsearch queries are done using the `Search` Eel helper. In case you want to retrieve a *list of nodes*, you'll generally do:

```
nodes = ${Search.query(site)....execute()}

```

In case you just want to retrieve a *single node*, the form of a query is as follows:

```
nodes = ${q(Search.query(site)....execute()).get(0)}

```

To fetch the total number of hits a query returns, the form of a query is as follows:

```
nodes = ${Search.query(site)....count()}

```

All queries search underneath a certain subnode. In case you want to search "globally", you will search underneath the current site node (like in the example above).

Furthermore, the following operators are supported:

As **value**, the following methods accept a simple type, a node object or a DateTime object.

Query OperatorDescription`nodeType('Your.Node:Type')`Filters on the given NodeType`exactMatch('propertyName', value)`Supports simple types: `exactMatch('tag', 'foo')`, or node references: `exactMatch('author', authorNode)``exclude('propertyName', value)`Excludes results by property - the negation of exactMatch.`greaterThan('propertyName', value, [clauseType])`Range filter with property values greater than the given value`greaterThanOrEqual('propertyName', value, [clauseType])`Range filter with property values greater than or equal to the given value`lessThan('propertyName', value, [clauseType])`Range filter with property values less than the given value`lessThanOrEqual('propertyName', value, [clauseType])`Range filter with property values less than or equal to the given value`sortAsc('propertyName')` / `sortDesc('propertyName')`Can also be used multiple times, e.g. `sortAsc('tag').sortDesc('date')` will first sort by tag ascending, and then by date descending.`limit(5)`Only return five results. If not specified, the default limit by Elasticsearch applies (which is at 10 by default)`from(5)`Return the results starting from the 6th one`prefix('propertyName', 'prefix', [clauseType])`Adds a prefix filter on the given field with the given prefix`geoDistance(propertyName, geoPoint, distance, [clauseType])`.Filters documents that include only hits that exists within a specific distance from a geo point.`fulltext('searchWord', options)`Does a query\_string query on the Fulltext index using the searchword and additional [options](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/query-dsl-query-string-query.html) to the query\_string. Recommendation: **use simpleQueryStringFulltext instead, as it yields better results and is more tolerant to user input**.`simpleQueryStringFulltext('searchWord', options)`Does a simple\_query\_string query on the Fulltext index using the searchword and additional [options](https://www.elastic.co/guide/en/elasticsearch/reference/8.3/query-dsl-simple-query-string-query.html) to the simple\_query\_string. Supports phrase matching like `"firstname lastname"` and tolerates broken input without exceptions (in contrast to `fulltext()`)`highlight(fragmentSize, fragmentCount, noMatchSize, field)`Configure result highlighting for every fulltext field individuallySearch Result Highlighting
--------------------------

[](#search-result-highlighting)

When using the `.fulltext()` or `.simpleQueryStringFulltext()` operator to do a fulltext, **highlight snippets** ([elasticsearch documentation](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/highlighting.html#highlighting)) are automatically queried. By default snippets with 150 characters are queried for all available fulltext fields with a 150 character fallback text.

To adjust this behavior you can first deactivate the default and then configure highlighting for every field individually:

```
Search.highlight(false).highlight(150, 2, 150, 'neos_fulltext.text').highlight(100, 1, 0, 'neos_fulltext.h2')

```

This deactivates the default highlighting and then queries 2 snipets of 150 characters each from hits in `neos_fulltext.text`, with a fallback to 150 characters of the beginning of the text if no match was found and additional 100 characters from `neos_fulltext.h2` without a fallback.

The highlight snippets can be accessed by

```
highlight = ${Search(...).execute().searchHitForNode(node).highlight}

```

moreLikeThis(like, fields, options)
-----------------------------------

[](#morelikethislike-fields-options)

The More Like This Query (MLT Query) finds documents that are "like" a given text or a given set of documents.

- `like` Single value or an array of strings or nodes.
- `fields` An array of fields which are used to compare other docs with the given "like" definition.
- `options` Additional options for the `more_like_this` query. See the [elasticsearch documentation](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-mlt-query.html) for what is possible.

Low-level operations
--------------------

[](#low-level-operations)

Furthermore, there is a more low-level operator which can be used to add arbitrary Elasticsearch filters:

- `queryFilter("filterType", {option1: "value1"}, [clauseType])`

The optional argument `clauseType` defaults to "must" and can be used to specify the boolean operator of the [bool query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html). It has to be one of `must`, `should`, `must_not` or `filter`.

At lowest level, there is the `request` operator which allows to modify the request in arbitrary manner. Note that the existing request is merged with the passed-in type in case it is an array:

- `request('query.filtered.query.bool.minimum_should_match', 1)`
- `request('query.filtered.query.bool', {"minimum_should_match": 1})`

In order to debug the query more easily, the following operation is helpful:

- `log()` log the full query on execution into the Elasticsearch log (i.e. in `Data/Logs/ElasticSearch.log`)

Example Queries
---------------

[](#example-queries)

### Finding all pages which are tagged in a special way and rendering them in an overview

[](#finding-all-pages-which-are-tagged-in-a-special-way-and-rendering-them-in-an-overview)

Use Case: On a "Tag Overview" page, you want to show all pages being tagged in a certain way

Setup: You have two node types in a blog called `Acme.Blog:Post` and `Acme.Blog:Tag`, both inheriting from `Neos.Neos:Document`. The `Post` node type has a property `tags` which is of type `references`, pointing to `Tag` documents.

Fusion setup:

```
 # for "Tag" documents, replace the main content area.
prototype(Neos.Neos:PrimaryContent).acmeBlogTag {
    condition = ${q(node).is('[instanceof Acme.Blog:Tag]')}
    type = 'Acme.Blog:TagPage'
}

 # The "TagPage"
prototype(Acme.Blog:TagPage) < prototype(Neos.Fusion:Collection) {
    collection = ${Search.query(site).nodeType('Acme.Blog:Post').exactMatch('tags', node).sortDesc('creationDate').execute()}
    itemName = 'node'
    itemRenderer = Acme.Blog:SingleTag
}
prototype(Acme.Blog:SingleTag) < prototype(Neos.Neos:Template) {
    ...
}

```

### Making OR queries

[](#making-or-queries)

There's no OR operator provided in this package, so you need to use a custom Elasticsearch query filter for that:

```
....queryFilter('bool', {should: [
    {term: {tags: tagNode.identifier}},
    {term: {places: tagNode.identifier}},
    {term: {projects: tagNode.identifier}}
]})

```

Aggregations
------------

[](#aggregations)

Aggregation is an easy way to aggregate your node data in different ways. Elasticsearch provides a couple of different types of aggregations. Check `https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html` for more info about aggregations. You can use them to get some simple aggregations like min, max or average values for your node data. Aggregations also allows you to build a complex filter for e.g. a product search or statistics.

**Aggregation methods**Right now there are two methods implemented. One generic `aggregation` function that allows you to add any kind of aggregation definition and a pre-configured `fieldBasedAggregation`. Both methods can be added to your TS search query. You can nest aggregations by providing a parent name.

- `aggregation($name, array $aggregationDefinition, $parentPath = NULL)` -- generic method to add a $aggregationDefinition under a path $parentPath with the name $name.
- `fieldBasedAggregation($name, $field, $type = 'terms', $parentPath = '', $size = 10)` -- adds a simple filed based Aggregation of type $type with name $name under path $parentPath. Used for simple aggregations like sum, avg, min, max or terms. By default 10 buckets are returned.

Examples
========

[](#examples)

Aggregations
------------

[](#aggregations-1)

### Add a average aggregation

[](#add-a-average-aggregation)

To add an average aggregation you can use the fieldBasedAggregation. This snippet would add an average aggregation for a property price:

```
nodes = ${Search.query(site)...fieldBasedAggregation("avgprice", "price", "avg").execute()}

```

Now you can access your aggregations inside your fluid template with

```
{nodes.aggregations}

```

### Create a nested aggregation

[](#create-a-nested-aggregation)

In this scenario you could have a node that represents a product with the properties price and color. If you would like to know the average price for all your colors you just nest an aggregation in your Fusion:

```
nodes = ${Search.query(site)...fieldBasedAggregation("colors", "color").fieldBasedAggregation("avgprice", "price", "avg", "colors").execute()}

```

The first `fieldBasedAggregation` will add a simple terms aggregation () with the name colors. So all different colors of your nodetype will be listed here. The second `fieldBasedAggregation` will add another sub-aggregation named avgprice below your colors-aggregation.

You can nest even more aggregations like this:

```
fieldBasedAggregation("anotherAggregation", "field", "avg", "colors.avgprice")

```

### Add a custom aggregation

[](#add-a-custom-aggregation)

To add a custom aggregation you can use the `aggregation()` method. All you have to do is to provide an array with your aggregation definition. This example would do the same as the fieldBasedAggregation would do for you:

```
aggregationDefinition = Neos.Fusion:DataStructure {
    terms = Neos.Fusion:DataStructure {
        field = "color"
    }
}
nodes = ${Search.query(site)...aggregation("color", this.aggregationDefinition).execute()}

```

#### Product filter

[](#product-filter)

This is a more complex scenario. With this snippet we will create a full product filter based on your selected Nodes. Imagine an NodeTye ProductList with an property `products`. This property contains a comma separated list of sku's. This could also be a reference on other products.

```
prototype(Vendor.Name:FilteredProductList) < prototype(Neos.Neos:Content)
prototype(Vendor.Name:FilteredProductList) {

    // Create SearchFilter for products
    searchFilter = Neos.Fusion:DataStructure {
        sku = ${String.split(q(node).property("products"), ",")}
    }

    # Search for all products that matches your queryFilter and add aggregations
    filter = ${Search.query(site).nodeType("Vendor.Name:Product").queryFilterMultiple(this.searchFilter, "must").fieldBasedAggregation("color", "color").fieldBasedAggregation("size", "size").execute()}

    # Add more filter if get/post params are set
    searchFilter.color = ${request.arguments.color}
    searchFilter.color.@if.onlyRenderWhenFilterColorIsSet = ${request.arguments.color != ""}
    searchFilter.size = ${request.arguments.size}
    searchFilter.size.@if.onlyRenderWhenFilterSizeIsSet = ${request.arguments.size != ""}

    # filter your products
    products = ${Search.query(site).nodeType("Vendor.Name:Product").queryFilterMultiple(this.searchFilter, "must").execute()}

    # don't cache this element
    @cache {
        mode = 'uncached'
        context {
            1 = 'node'
            2 = 'site'
        }
    }

```

In the first lines we will add a new searchFilter variable and add your selected sku's as a filter. Based on this selection we will add two aggregations of type terms. You can access the filter in your template with `{filter.aggregations}`. With this information it is easy to create a form with some select fields with all available options. If you submit the form just call the same page and add the get parameter color and/or size. The next lines will parse those parameters and add them to the searchFilter. Based on your selection all products will be fetched and passed to your template.

**Important notice**

If you do use the terms filter be aware of Elasticsearchs analyze functionality for strings. You might want to disable this for all your filterable properties, or else filtering won't work on them properly:

```
'Vendor.Name:Product'
  properties:
    color:
      type: string
      defaultValue: ''
      search:
        elasticSearchMapping:
          type: keyword
```

Sorting
-------

[](#sorting)

This package adapts Elasticsearchs sorting capabilities. You can add multiple sort operations to your query. Right now there are three methods you can use:

- `sortAsc('propertyName')`
- `sortDesc('propertyName')`
- `sort('configuration')`

Just append those method to your query like this:

```
# Sort ascending by property title

nodes = ${q(Search.query(site).....sortAsc("title").execute())}

# Sort for multiple properties

nodes = ${q(Search.query(site).....sortAsc("title").sortDesc("name").execute())}

# Custom sort operation

geoSorting = Neos.Fusion:DataStructure {
    _geo_distance = Neos.Fusion:DataStructure {
        latlng = Neos.Fusion:DataStructure {
            lat = 51.512711
            lon = 7.453084
        }
        order = "plane"
        unit = "km"
        distance_type = "sloppy_arc"
    }
}
nodes = ${Search.query(site).....sort(this.geoSorting).execute()}

```

Check  for more configuration options.

### Example with pagination and sort by distance

[](#example-with-pagination-and-sort-by-distance)

This is how a more complex example could look like. Imagine you a want to render a list of nodes and in addition to each node you want to display the distance to a specific point.

First of all you have to define a property in your NodeTypes.yaml for your node where to store lat/lon information's:

```
'Vendor.Name:Retailer':
  properties:
    'latlng':
      type: string
      search:
        elasticSearchMapping:
          type: "geo_point"
```

Query your nodes in your Fusion:

```
    geoSorting = Neos.Fusion:DataStructure {
	_geo_distance {
	    geopoint {
		lat = 51.512711
	        lon = 7.453084
	    }
	    order = "asc"
	    unit = "km"
	    ignore_unmapped = true
	}
    }

nodes = ${Search.query(site).nodeType('Vendor.Name:Retailer').sort(this.geoSorting)}

```

Now you can paginate that nodes in your template. To get your actually distance for each node use the `GetHitArrayForNodeViewHelper`:

```
{namespace cr=Neos\ContentRepository\Search\ViewHelpers}
{namespace es=Flowpack\ElasticSearch\ContentRepositoryAdaptor\ViewHelpers}

        {singleNode.name} -

```

The ViewHelper will use \\Neos\\Utility\\Arrays::getValueByPath() to return a specified path. So you can make use of an array or a string. Check the documentation \\Neos\\Utility\\Arrays::getValueByPath() for more information.

**Important notice**

The ViewHelper GetHitArrayForNode will return the raw hit result array. The path property allows you to access some specific data like the the sort data. If there is only one value for your path the value will be returned. If there is more data the full array will be returned by GetHitArrayForNode-VH. So you might have to use the ForViewHelper to access your sort values.

Fulltext Search / Indexing
--------------------------

[](#fulltext-search--indexing)

When searching in a fulltext index, we want to show Pages, or, generally speaking, everything which is a `Document` node. However, the main content of a certain `Document` is often not stored in the node itself, but inside its (`Content`) child nodes.

This is why we need some special functionality for indexing, which *adds the content of the inner nodes* to the `Document` nodes where they belong to, to a field called `neos_fulltext` and `neos_fulltext_parts`.

Furthermore, we want that a fulltext match e.g. inside a headline is seen as *more important* than a match inside the normal body text. That's why the `Document` node not only contains one field with all the texts, but multiple "buckets" where text is added to: One field which contains everything deemed as "very important" (`neos_fulltext.h1`), one which is "less important" (`neos_fulltext.h2`), and finally one for the plain text (`neos_fulltext.text`). All of these fields are configured with different `boost` values.

**For a search user interface, checkout the Flowpack.SearchPlugin package**

Suggestions
-----------

[](#suggestions)

Elasticsearch offers an easy way to get query suggestions based on your query. Check `https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html` for more information about how you can build and use suggestion in your search.

**Suggestion methods implemented**

There are two methods implemented. `suggestions` is a generic one that allows to build the suggestion query of your dreams. The other method is `termSuggestions` and is meant for basic term suggestions. They can be added to your totaly awesome TS search query.

- `suggestions($name, array $suggestionDefinition)` -- generic method to be filled with your own suggestionQuery
- `termSuggestions($term, $field = '_all', $name = 'suggestions'` -- simple term suggestion query on all fields

### Examples

[](#examples-1)

#### Add a simple suggestion to a query

[](#add-a-simple-suggestion-to-a-query)

Simple suggestion that returns a suggestion based on the sent term

```
suggestions = ${Search.query(site)...termSuggestions('someTerm')}

```

You can access your suggestions inside your fluid template with

```
{nodes.suggestions}

```

### Add a custom suggestion

[](#add-a-custom-suggestion)

Phrase query that returns query suggestions

```
suggestionsQueryDefinition = Neos.Fusion:DataStructure {
    text = 'some Text'
    simple_phrase = Neos.Fusion:DataStructure {
        phrase = Neos.Fusion:DataStructure {
            analyzer = 'body'
            field = 'bigram'
            size = 1
            real_world_error_likelihood = 0.95
            ...
        }
    }
}
suggestions = ${Search.query(site)...suggestions('my_suggestions', this.suggestionsQueryDefinition)}

```

Debugging
---------

[](#debugging)

In order to understand what's going on, the following might be helpful:

- use `./flow nodeindex:showMapping` to show the currently defined Elasticsearch Mapping
- use the `.log()` statement inside queries to dump them to the Elasticsearch Log
- the logfile `Data/Logs/ElasticSearch.log` contains loads of helpful information.

**Settings.yaml**

1. Change the base namespace for configuration from `Flowpack.ElasticSearch.ContentRepositoryAdaptor`to `Neos.ContentRepository.Search`. All further adjustments are made underneath this namespace:
2. (If it exists in your configuration:) Move `indexName` to `elasticSearch.indexName`
3. (If it exists in your configuration:) Move `log` to `elasticSearch.log`
4. search for `mapping` (inside `defaultConfigurationPerType.`) and replace it by `elasticSearchMapping`.
5. Inside the `indexing` expressions (at `defaultConfigurationPerType.`), replace `ElasticSearch.` by `Indexing.`.

**NodeTypes.yaml**

1. Replace `elasticSearch` by `search`. This replaces both `.elasticSearch`and `.properties..elasticSearch`.
2. search for `mapping` (inside `.properties..search`) and replace it by `elasticSearchMapping`.
3. Replace `ElasticSeach.fulltext` by `Indexing`
4. Search for `ElasticSearch.` (inside the `indexing` expressions) and replace them by `Indexing.`

###  Health Score

67

—

FairBetter than 100% of packages

Maintenance74

Regular maintenance activity

Popularity50

Moderate usage in the ecosystem

Community39

Small or concentrated contributor base

Maturity91

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~49 days

Recently: every ~60 days

Total

87

Last Release

104d ago

Major Versions

7.0.8 → 8.1.12022-01-04

7.0.9 → 8.2.02022-02-16

7.0.x-dev → 8.5.02023-11-01

8.5.1 → 9.0.02025-04-02

8.5.2 → 9.0.12025-05-28

PHP version history (7 changes)2.0.0PHP &gt;=5.5.0

4.0.5PHP &gt;=7.0

5.0.0PHP ^7.2

8.0.0PHP ^7.3

8.1.1PHP ^7.3 || ^8.0

9.0.0PHP ^8.2

8.5.4PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/41de3ce33f7278b208dbea830e89b8ff1349fa145d8508127c89d4d94f6f34b0?d=identicon)[Nezaniel](/maintainers/Nezaniel)

![](https://www.gravatar.com/avatar/25d49a6af82b72d2764774a05c307808375016d7aeaaef3862472a6580ff38a7?d=identicon)[flowpack](/maintainers/flowpack)

---

Top Contributors

[![daniellienert](https://avatars.githubusercontent.com/u/642226?v=4)](https://github.com/daniellienert "daniellienert (445 commits)")[![kdambekalns](https://avatars.githubusercontent.com/u/95873?v=4)](https://github.com/kdambekalns "kdambekalns (197 commits)")[![dfeyer](https://avatars.githubusercontent.com/u/221173?v=4)](https://github.com/dfeyer "dfeyer (141 commits)")[![skurfuerst](https://avatars.githubusercontent.com/u/190777?v=4)](https://github.com/skurfuerst "skurfuerst (98 commits)")[![gerhard-boden](https://avatars.githubusercontent.com/u/10533739?v=4)](https://github.com/gerhard-boden "gerhard-boden (67 commits)")[![mgoldbeck](https://avatars.githubusercontent.com/u/1336044?v=4)](https://github.com/mgoldbeck "mgoldbeck (24 commits)")[![johannessteu](https://avatars.githubusercontent.com/u/769789?v=4)](https://github.com/johannessteu "johannessteu (19 commits)")[![robertlemke](https://avatars.githubusercontent.com/u/95582?v=4)](https://github.com/robertlemke "robertlemke (10 commits)")[![hlubek](https://avatars.githubusercontent.com/u/33351?v=4)](https://github.com/hlubek "hlubek (10 commits)")[![dlubitz](https://avatars.githubusercontent.com/u/13046100?v=4)](https://github.com/dlubitz "dlubitz (10 commits)")[![dimaip](https://avatars.githubusercontent.com/u/837032?v=4)](https://github.com/dimaip "dimaip (8 commits)")[![ComiR](https://avatars.githubusercontent.com/u/11410095?v=4)](https://github.com/ComiR "ComiR (8 commits)")[![Nikdro](https://avatars.githubusercontent.com/u/9807101?v=4)](https://github.com/Nikdro "Nikdro (7 commits)")[![remuslazar](https://avatars.githubusercontent.com/u/6108134?v=4)](https://github.com/remuslazar "remuslazar (7 commits)")[![paxuclus](https://avatars.githubusercontent.com/u/15905038?v=4)](https://github.com/paxuclus "paxuclus (6 commits)")[![radmiraal](https://avatars.githubusercontent.com/u/324613?v=4)](https://github.com/radmiraal "radmiraal (5 commits)")[![kitsunet](https://avatars.githubusercontent.com/u/324408?v=4)](https://github.com/kitsunet "kitsunet (4 commits)")[![mocdk-dev](https://avatars.githubusercontent.com/u/4737313?v=4)](https://github.com/mocdk-dev "mocdk-dev (4 commits)")[![bwaidelich](https://avatars.githubusercontent.com/u/307571?v=4)](https://github.com/bwaidelich "bwaidelich (4 commits)")[![gjwnc](https://avatars.githubusercontent.com/u/19683930?v=4)](https://github.com/gjwnc "gjwnc (3 commits)")

---

Tags

elasticsearchhacktoberfestneoscms

### Embed Badge

![Health badge](/badges/flowpack-elasticsearch-contentrepositoryadaptor/health.svg)

```
[![Health](https://phpackages.com/badges/flowpack-elasticsearch-contentrepositoryadaptor/health.svg)](https://phpackages.com/packages/flowpack-elasticsearch-contentrepositoryadaptor)
```

###  Alternatives

[neos/neos

An open source Content Application Platform based on Flow. A set of core Content Management features is resting within a larger context that allows you to build a perfectly customized experience for your users.

116989.0k674](/packages/neos-neos)[flowpack/searchplugin

Plugin for search integration via content node

24257.5k1](/packages/flowpack-searchplugin)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[neos/media

The Media package

101.1M45](/packages/neos-media)[neos/content-repository-search

Common code and interface for a Neos CR search implementation

10413.3k4](/packages/neos-content-repository-search)[flowpack/simplesearch-contentrepositoryadaptor

Implements a bridge to search in Neos CR via the flowpack/simplesearch package.

2330.9k](/packages/flowpack-simplesearch-contentrepositoryadaptor)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
