# Creating index with field type keyword in app search

**URL:** https://discuss.elastic.co/t/creating-index-with-field-type-keyword-in-app-search/344178
**Category:** Elastic Search
**Tags:** docker, elastic-app-search
**Created:** [October 1, 2023, 12:33am UTC](https://discuss.elastic.co/t/creating-index-with-field-type-keyword-in-app-search/344178 "2023-10-01T00:33:53Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![kabilsharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kabilsharma/32/100503_2.png) [@kabilsharma](https://discuss.elastic.co/u/kabilsharma)
#### Post date: [October 1, 2023, 12:33am UTC](https://discuss.elastic.co/t/creating-index-with-field-type-keyword-in-app-search/344178/1 "2023-10-01T00:33:53Z")

</div>

We are using docker compose to self manage elastic enterprise search , kibana and Elasticsearch 8.4.1 . license Gold

Everything works fine but as we are trying to create geocoding search engine giving us some issues.

we have columns like

Name Text  
District\_name keyword  
Category keyword  
address keyword  
phone-no text  
location lat, long

now i have two problems

First is when we ingest data with app search pipeline it converts data in text search which results category , district \_name as full text search and we need them to be keyword search only.

we tried creating engine from index , create index and ingest data ( this engine is managed by Elasticsearch ) . But seems doesn't get it through properly as we were missing something . no errors in particular.

how to allow app search to use keyword as text field .

--second issue is we beleive is because of full text or keywords.

when we search pizza we get matchings at top with name pizza pizza ( two consecutive words) how we can stop this behaviour.

Also experiencing an performance issue when searching using proximity boost first five results are in correct proximity but for example

pizza

a pizza 20 mtr  
b pizza 50 mtr  
c pizza 4 km  
d pizza 200 km  
e pizza 56 km  
f pizza 30 mtr .

Only searching with two column name and proximity. Name is same pizza no other text . What could be the issue? Why location proximity works for first few and not for the rest.

is there a simpler documentation or link to a video which will tell you how to create index , ingest data with app search but with your own mapping. All in app search not plain Elasticsearch.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [October 2, 2023, 2:33am UTC](https://discuss.elastic.co/t/creating-index-with-field-type-keyword-in-app-search/344178/2 "2023-10-02T02:33:39Z")

</div>

There is no actual `keyword` in App Search you just query the field different in 8.4 that is a value filter, take a look at this

> **[Search API filters | Elastic App Search Documentation \[8.4\] | Elastic](https://www.elastic.co/guide/en/app-search/8.4/filters.html)**

So in short an App Search `text` field in App Search is both full text and keyword

---

<div class="post-metadata">

### Author: ![Carlos\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_d/32/126245_2.png) [@Carlos\_D](https://discuss.elastic.co/u/Carlos_D)
#### Post date: [October 2, 2023, 7:14am UTC](https://discuss.elastic.co/t/creating-index-with-field-type-keyword-in-app-search/344178/3 "2023-10-02T07:14:39Z")

</div>

> [@kabilsharma](#):
>
> when we search pizza we get matchings at top with name pizza pizza ( two consecutive words) how we can stop this behaviour.

You'll need to check both [precision tuning](https://www.elastic.co/guide/en/app-search/current/precision-tuning.html) and [relevance tuning](https://www.elastic.co/guide/en/app-search/current/relevance-tuning-guide.html) for fine-tuning your results. When looking for text, it's normal that results with more frequency of the terms that you're searching for come first. Are there other fields that you could search for as well? Or other criteria to make other results come on top of those?

> when searching using proximity boost first five results are in correct proximity but for example

This could be a problem with the `function` you're using for the boost value (see [proximity boosts](https://www.elastic.co/guide/en/app-search/current/boosts.html#boosts-proximity-boosts) function). Most probably it is decaying too quickly for results that are farther away than a specific limit, and thus boosting is not enough to make them being ordered in terms of distance.

If geolocation is really important, you could try [sorting by location](https://www.elastic.co/guide/en/app-search/current/sort.html#sort-geolocation-sorting) directly. Otherwise, I think you can experiment with the `function` and `factor` parameters for the proximity boost. Also, removing results that are too far away using [geo filters](https://www.elastic.co/guide/en/app-search/current/filters.html#filters-geo-filters) could get rid of unwanted results.

> is there a simpler documentation or link to a video which will tell you how to create index , ingest data with app search but with your own mapping

App Search abstracts you away from having to create your mapping. You can change your schema dynamically, thus not needing to create a mapping up front. In case you want to use App Search with a custom mapping, you can check [Elasticsearch index engines](https://www.elastic.co/guide/en/app-search/current/elasticsearch-engines.html) for creating an App Search engine with an existing Elasticsearch index.

Keep in mind that this is a more advanced use case than directly creating an engine for App Search, as it involves you creating the index and adhering to specific [field conventions](https://www.elastic.co/guide/en/app-search/current/elasticsearch-engines-text-subfields-support-conventions.html) so App Search features work correctly.

I hope that helps!

---

<div class="post-metadata">

### Author: ![kabilsharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kabilsharma/32/100503_2.png) [@kabilsharma](https://discuss.elastic.co/u/kabilsharma)
#### Post date: [October 5, 2023, 6:10am UTC](https://discuss.elastic.co/t/creating-index-with-field-type-keyword-in-app-search/344178/4 "2023-10-05T06:10:55Z")

</div>

cool. so when we call search api we tell it to be consider a field as a 'keyword' right? that what you mean. Please share the link if it is correct. [Search API filters | Elastic App Search Documentation [8.4] | Elastic](https://www.elastic.co/guide/en/app-search/8.4/filters.html#filters-value-filters) . trying to understand the link shared havent got to an undeerandding how to do it. already exlained about schema and use case.

---

<div class="post-metadata">

### Author: ![kabilsharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kabilsharma/32/100503_2.png) [@kabilsharma](https://discuss.elastic.co/u/kabilsharma)
#### Post date: [October 5, 2023, 6:20am UTC](https://discuss.elastic.co/t/creating-index-with-field-type-keyword-in-app-search/344178/5 "2023-10-05T06:20:45Z")

</div>

Thanks carlos for you reply. For the proximity boost issue we are trying to do this as mention here as a woraround to get better results [Geo location distance sorting by proximity boost](https://discuss.elastic.co/t/geo-location-distance-sorting-by-proximity-boost/270749).

The thing about the mapping is we are just creating a very simple search engine with name and district\_name search. As i mention i ingestion works fine but when we try to update schema we have only four option( now five nested ) . It doesnt have keyword in it. So all together we need to see as stephenb suggested to query as keyword which is new approach for me . I appreaciate if you can understand my use case and suggest how to get desire results .

we have columns like

Name Text  
District\_name keyword  
Category keyword  
address keyword  
phone-no text  
location lat, long

if elastic\_search ingest District\_name ,Category ,address as text how i can still restrict them to do only keyword search on these columns instead of full text search. Thanks in advance

---

<div class="post-metadata">

### Author: ![Carlos\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_d/32/126245_2.png) [@Carlos\_D](https://discuss.elastic.co/u/Carlos_D)
#### Post date: [October 5, 2023, 8:28am UTC](https://discuss.elastic.co/t/creating-index-with-field-type-keyword-in-app-search/344178/6 "2023-10-05T08:28:45Z")

</div>

If you're using App Search, there is no keyword field - it is implicitly added for you. You define the field as text in the schema view.

If you don't need to perform full text search, you can use filters to limit the results you'll get. For example, if you want to only get results from a specific district, you would do:

```auto
POST /api/as/v1/engines/<engine>/search
{
  "query": "your-query-here",
  "filters" : {
    "District_name": ["district-name-you-want-to-look-for"]
  }
}

```

If I got correctly your use case, you're looking for the closest results to a specific point (for example, 37.386483, -122.083842) that are in a specific district at a radius of for example 3 km at the most.

You could issue the following query for that:

```auto

POST /api/as/v1/engines/<engine>/search
{
  "query": "",
  "sort": [
    {
      "location": {
        "center": "37.386483, -122.083842",
        "order": "asc"
      }
    }
  ],
  "all": [
    {
      "District_name": [
        "district-name-you-want-to-look-for"
      ]
    },
    {
      "location": {
        "center": "37.386483, -122.083842",
        "distance": 3,
        "unit": "km"
      }
    }
  ]
}

```

See that I set the query to empty to specify that we don't need to search for anything and all results that match the filters will be returned, in the specified sort order.

Is this what you're looking for?

---

<div class="post-metadata">

### Author: ![kabilsharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kabilsharma/32/100503_2.png) [@kabilsharma](https://discuss.elastic.co/u/kabilsharma)
#### Post date: [October 5, 2023, 1:22pm UTC](https://discuss.elastic.co/t/creating-index-with-field-type-keyword-in-app-search/344178/7 "2023-10-05T13:22:46Z")

</div>

Sorry I made this confusing and hard to understand. The real use case is people will search in name not district\_name. So for example

Pizza  
dominos  
MacDonald

it will fetch nearest location with name have pizza in it . but many cases people search for something in different district or city like

hotel in new york  
restaurant in delhi  
temple in london

like that.

so if new york or delhi and london is fully matched then it would add some score to results.

if user searches

long door office ---- it should not match with district\_name london.

Hope you got my point . Currently it is matching some of the letters from district \_name .

---

<div class="post-metadata">

### Author: ![Carlos\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_d/32/126245_2.png) [@Carlos\_D](https://discuss.elastic.co/u/Carlos_D)
#### Post date: [October 6, 2023, 8:06am UTC](https://discuss.elastic.co/t/creating-index-with-field-type-keyword-in-app-search/344178/8 "2023-10-06T08:06:16Z")

</div>

Understood, thanks for explaining!

App Search does not provide a per-field precision tuning. That means that precision for allowing fuzzy and prefix matching is effective on all fields that you're searching.

You could achieve this creating a new index, with a similar mapping from the current engine index (which would be `.ent-search-engine-documents-<your-engine-name>`). In this new mapping, you can use `keyword` fields for your district data so it is not affected by analysis.

Once your index is created, create an [Elasticsearch based engine](https://www.elastic.co/guide/en/app-search/current/elasticsearch-engines-create.html) using the new index.

This should achieve the results you're expecting.

Hope that helps!

---

<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: [November 3, 2023, 8:06am UTC](https://discuss.elastic.co/t/creating-index-with-field-type-keyword-in-app-search/344178/9 "2023-11-03T08:06:59Z")

</div>

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