[role="xpack"]
[[post-analytics-collection-event]]
=== Post Event to an Analytics Collection

beta::[]

++++
<titleabbrev>Post Analytics Collection Event</titleabbrev>
++++

.New API reference
[sidebar]
--
For the most up-to-date API details, refer to {api-es}/group/endpoint-analytics[Behavioral analytics APIs].
--

////
[source,console]
----
PUT _application/analytics/my_analytics_collection
----
// TESTSETUP

[source,console]
----
DELETE _application/analytics/my_analytics_collection
----
// TEARDOWN
////

Post an event to a <<behavioral-analytics-overview,Behavioral Analytics>> Collection.

[[post-analytics-collection-event-request]]
==== {api-request-title}

`POST _application/analytics/<collection_name>/event/<event_type>`

[[post-analytics-collection-event-path-params]]
==== {api-path-parms-title}

`<collection_name>`::
(Required, string) Analytics collection name you want to ingest event in.

`<event_type>`::
(Required, string) Analytics event type. Can be one of `page_view`, `search`, `search_click`.

[[post-analytics-collection-event-request-body]]
==== {api-request-body-title}

Full request body parameters can be found in: <<behavioral-analytics-event-reference>>.

[[post-analytics-collection-event-prereqs]]
==== {api-prereq-title}

Requires the `post_behavioral_analytics_event` cluster privilege.

[[post-analytics-collection-event-response-codes]]
==== {api-response-codes-title}

`202`::
Event has been accepted and will be ingested.

`404`::
Analytics Collection `<collection_name>` does not exists.

`400`::
Occurs either when the event type is unknown or when event payload contains invalid data.

[[post-analytics-collection-event-example]]
==== {api-examples-title}

The following example send a `search_click` event to an Analytics Collection called `my_analytics_collection`:

[source,console]
----
POST _application/analytics/my_analytics_collection/event/search_click
{
  "session": {
    "id": "1797ca95-91c9-4e2e-b1bd-9c38e6f386a9"
  },
  "user": {
    "id": "5f26f01a-bbee-4202-9298-81261067abbd"
  },
  "search":{
    "query": "search term",
    "results": {
      "items": [
        {
          "document": {
            "id": "123",
            "index": "products"
          }
        }
      ],
      "total_results": 10
    },
    "sort": {
      "name": "relevance"
    },
    "search_application": "website"
  },
  "document":{
    "id": "123",
    "index": "products"
  }
}
----
