# App Search API Keys Basic Analytics Info

**URL:** <https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [April 19, 2023, 12:56pm UTC](https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307 "2023-04-19T12:56:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![alongaks](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@alongaks](https://discuss.elastic.co/u/alongaks)\
**Post date:** [April 19, 2023, 12:56pm UTC](https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307/1 "2023-04-19T12:56:16Z")

</div>

Hello,

I have a v8.7 deployment using App Search to crawl websites, indexing content. The site search experience is working nicely. However, I am wondering about the 'Recent queries' stats at the bottom of the page from Kibana \> Enterprise Search \> App Search \> Engines - [meta-enginename] \> **Analytics**.

In this area, I understand in order to get the full analytic functionality like 'click analytics' requires adding in necessary API configs to track the relevant info. [Analytics APIs | App Search documentation [8.7] | Elastic](https://www.elastic.co/guide/en/app-search/current/analytics.html)

When using the Credentials \> API Keys - search-key (type: Public Search Key, Modes: search), I believe the one created with App Search by default, queries shows up in the 'Recent queries' list in the 'Analytics' page of the meta-engine. No custom code is required in the site search box on the webpage for this to work. This functionality is what is desired for the below scenario.

If someone uses a created API key in Credentials \> API Keys - name-of-created-key (type: Private API Key, Modes: read-only), these queries are only showing up in the API logs, but not in the 'Recent queries' list.

Is it possible to get 'Recent queries' to show up in the 'Analytics' page for a 'private api key'/read-only mode key?

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [April 19, 2023, 1:01pm UTC](https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307/2 "2023-04-19T13:01:19Z")

</div>

Hey!

Is there a particular reason why you need to use a private key instead of a search key? Would help understand the reasoning why you need to use a private key there.

Joe

---

<div class="post-metadata">

**Author:** ![alongaks](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@alongaks](https://discuss.elastic.co/u/alongaks)\
**Post date:** [April 19, 2023, 1:06pm UTC](https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307/3 "2023-04-19T13:06:10Z")

</div>

Hi, Joe! Appreciate the quick response!

The website search is being provided in two environments - one is a public facing site, the other an 'intranet' site. I believe preference is to not have search queries/resultant data 'leaked' over-the-air, if that makes sense?

I'm not one of the site devs that is using/codifying the search functionality, but I will ask for clarification.

It was something I noticed as of recent and figured it would be ideal to continue to capture that info in some way, even if a private, read-only API key is in use.

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [April 19, 2023, 2:47pm UTC](https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307/4 "2023-04-19T14:47:38Z")

</div>

Could be that you are sharing one index between intranet and public facing site, with a signed key to only search a specific set of documents for public consumption? Would be good to hear more about your setup.

Ill find out the differences between search vs signed key in analytics 🙂

Joe

---

<div class="post-metadata">

**Author:** ![alongaks](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@alongaks](https://discuss.elastic.co/u/alongaks)\
**Post date:** [April 24, 2023, 2:35pm UTC](https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307/5 "2023-04-24T14:35:23Z")

</div>

Found out a bit more info about the use of the API keys in App Search.

Apparently there are limitations with the default App Search 'search' API that an Elasticsearch API allows.

Below is an example query that is run using the manually created private-key pointing to Elasticsearch

```auto
curl -X POST 'http://URL.com:3002/api/as/v1/engines/meta-engine/elasticsearch/_search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-redacted' \
-d '{"from":0,"size":10,"query":{"bool":{"must":{"multi_match":{"query":"rubbish","fields":[]}},"should":[{"wildcard":{"url":"*.php"}},{"wildcard":{"url":"*.php?*"}},{"wildcard":{"url":"*\/"}}],"minimum_should_match":1}}}'

```

That comes back with an error...

```auto
{"errors":["Authentication method not allowed. Allowed methods: Private API key."]}

```

But if you run the following query, there are differences in what is available to use in the query, presumably

```auto
curl -X POST 'http://URL.com:3002/api/as/v1/engines/meta-engine/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-redacted' \
-d '{"from":0,"size":10,"query":{"bool":{"must":{"multi_match":{"query":"rubbish","fields":[]}},"should":[{"wildcard":{"url":"*.php"}},{"wildcard":{"url":"*.php?*"}},{"wildcard":{"url":"*\/"}}],"minimum_should_match":1}}}'

```

... as that returns

```auto
{"errors":["Options contains invalid keys: from and size","Query must be a string or number"]}

```

Can the basic analytics that the default App Search 'public search' API pulls in be obtained when querying against `meta-engine/elasticsearch/_search`?

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [April 24, 2023, 7:38pm UTC](https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307/6 "2023-04-24T19:38:59Z")

</div>

Right! This makes sense why you need to use the private-key. \_search endpoint requires the admin key to use and is designed not to be used directly (on the browser) but integrated with your API server.

You have probably discovered this already but the app-search search API and elasticsearch/\_search endpoints are very different.

CORRECTION: You can emit analytics events via the passthrough \_search endpoint using the analytics headers [Elasticsearch search API for App Search | App Search documentation [8.7] | Elastic](https://www.elastic.co/guide/en/app-search/current/elasticsearch-search-api-reference.html#elasticsearch-search-api-reference-analytics-parameters)

Joe

---

<div class="post-metadata">

**Author:** ![alongaks](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@alongaks](https://discuss.elastic.co/u/alongaks)\
**Post date:** [April 24, 2023, 8:29pm UTC](https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307/7 "2023-04-24T20:29:19Z")

</div>

Thanks for the responses, Joe!

I noticed this in documentation, possibly for Elasticsearch API: [Elasticsearch search API for App Search | App Search documentation [8.7] | Elastic](https://www.elastic.co/guide/en/app-search/current/elasticsearch-search-api-reference.html#elasticsearch-search-api-reference-analytics-parameters)

It mentions using the 'X-Enterprise-Search-Analytics' header in the API requests. So I tried it a couple ways, neither of them error out, but one has different analytics results and the other appears to have no analytics result logged.

This one has a result logged into analytics

```auto
curl -X POST 'http://URL.com:3002/api/as/v1/engines/meta-engine/elasticsearch/_search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-redacted' \
-H 'X-Enterprise-Search-Analytics: true' \
-d '{"from":0,"size":10,"query":{"bool":{"must":{"multi_match":{"query":"rubbish","fields":[]}},"should":[{"wildcard":{"url":"*.php"}},{"wildcard":{"url":"*.php?*"}},{"wildcard":{"url":"*\/"}}],"minimum_should_match":1}}}'

```

But it logs the word 'true' not the actual search query being run.

If I do it as just `-H 'X-Enterprise-Search-Analytics'` it doesn't log anything. I'm wondering if there is a different syntax needed to enable the tracking since it seems to work somewhat without errors, using the private key?

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [April 25, 2023, 8:33am UTC](https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307/8 "2023-04-25T08:33:38Z")

</div>

Oh you're right! I completely forgot about that addition!

So the value needs to be the query text. In your example it would need to be

-H 'X-Enterprise-Search-Analytics: rubbish' \

We cant unfortunately take the query value you added as with \_search, you can specify one or more match conditions with different query text. This header allows you to specify the query you want to appear in analytics.

You can also add tags to the analytics query via another header with

-H 'X-Enterprise-Search-Analytics-Tags: tag1,tag2' \

Hope this helps and thanks for flagging.

Joe

---

<div class="post-metadata">

**Author:** ![alongaks](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@alongaks](https://discuss.elastic.co/u/alongaks)\
**Post date:** [April 25, 2023, 12:03pm UTC](https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307/9 "2023-04-25T12:03:46Z")

</div>

Much appreciated!

🤜 🤛

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 23, 2023, 12:04pm UTC](https://discuss.elastic.co/t/app-search-api-keys-basic-analytics-info/330307/10 "2023-05-23T12:04:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
