# Can we Search only by one field (f.e. title, description etc.)?

**URL:** https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681
**Category:** Elastic Search
**Tags:** elastic-app-search
**Created:** [January 18, 2022, 10:41am UTC](https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681 "2022-01-18T10:41:29Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![roman.bliztsv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roman.bliztsv/32/100463_2.png) [@roman.bliztsv](https://discuss.elastic.co/u/roman.bliztsv)
#### Post date: [January 18, 2022, 10:41am UTC](https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681/1 "2022-01-18T10:41:29Z")

</div>

I've created a config using your documentation.

```auto
const config = {
  searchQuery: {
    result_fields: {
      art_title: { raw: {}},
      cra_url_doc: { raw: {}},
      art_fulltext: {
        snippet: {
          size: 700,
          fallback: true
        }
      },
      thumbnail_url: {raw: {} },
      tags: {raw: {} },
      art_date_published: {raw: {}}
    },
    search_fields: {
      "art_title": {
        "weight": 10
      },
      "cra_url_doc": {},
    },
    facets: {
      entity_labels: { type: "value",size: 250},
      cra_application: { type: "value", size: 250},
      tags: { type: "value", size: 250},
      art_date_published: {
        type: "range",
        ranges: [
          {
            from: moment().subtract(1, "days").toISOString(),
            name: "Innerhalb des letzten Tages"
          },
          {
            from: moment()
              .subtract(7, "days")
              .toISOString(),
            name: "Innerhalb der letzten 7 Tage"
          },
          {
            from: moment()
              .subtract(30, "days")
              .toISOString(),
            name: "Innerhalb der letzten 30 Tage"
          },
          {
            from: moment()
              .subtract(364, "days")
              .toISOString(),
            name: "Innerhalb des letzten Jahres"
          }
        ]
      }
    }
  },
  autocompleteQuery: buildAutocompleteQueryConfig(),
  apiConnector: connector,
  alwaysSearchOnInitialLoad: true
};

```

Unfortunately I cannot find any helpful information about how to set the search fields so that I can search only by **app\_title** , in my case (as you can see in the code).  
So, is it even possible to specify by which fields I would like to search, currently its searching by each filed and highlighting it. Attaching a screenshot.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/3/23748cc42c9374db16f530ad05bdd6e997b90f6a.png)

---

<div class="post-metadata">

### Author: ![roman.bliztsv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roman.bliztsv/32/100463_2.png) [@roman.bliztsv](https://discuss.elastic.co/u/roman.bliztsv)
#### Post date: [January 18, 2022, 12:55pm UTC](https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681/2 "2022-01-18T12:55:16Z")

</div>

Can someone help me out with this question ?

Would be great to at least know is it possible to do it using Elasticsearch api 🙂.

---

<div class="post-metadata">

### Author: ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)
#### Post date: [January 18, 2022, 5:17pm UTC](https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681/3 "2022-01-18T17:17:59Z")

</div>

Hey. Yes, you can absolutely specify which fields to search by. That's what the `search_fields` that you have set should be doing.

---

<div class="post-metadata">

### Author: ![roman.bliztsv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roman.bliztsv/32/100463_2.png) [@roman.bliztsv](https://discuss.elastic.co/u/roman.bliztsv)
#### Post date: [January 18, 2022, 5:23pm UTC](https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681/4 "2022-01-18T17:23:03Z")

</div>

Thanks for answering  
But as I've sent the screenshot you can see that it's not working at all. It's even highlighting the word "Microsoft" for me.

I mean, if for example we are searching for query - "Microsoft", and some item have it inside of the description - it will take it.

I need to be able to choose dynamically whether I want to search by the `art-title` (as I have in my config) or by `art-fulltext`, or even both.

---

<div class="post-metadata">

### Author: ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)
#### Post date: [January 18, 2022, 5:25pm UTC](https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681/5 "2022-01-18T17:25:23Z")

</div>

Ok, let me put together a sandbox quick so we have something we can both look at and debug.

---

<div class="post-metadata">

### Author: ![roman.bliztsv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roman.bliztsv/32/100463_2.png) [@roman.bliztsv](https://discuss.elastic.co/u/roman.bliztsv)
#### Post date: [January 18, 2022, 5:25pm UTC](https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681/6 "2022-01-18T17:25:54Z")

</div>

Great, thanks a lot !

Ping me in here when you will make the sandbox 🙂

---

<div class="post-metadata">

### Author: ![roman.bliztsv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roman.bliztsv/32/100463_2.png) [@roman.bliztsv](https://discuss.elastic.co/u/roman.bliztsv)
#### Post date: [January 19, 2022, 8:28am UTC](https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681/8 "2022-01-19T08:28:50Z")

</div>

Hey, I guess I may found the issue

```auto
result_fields: {
      art_title: { raw: {}},
      cra_url_doc: { raw: {}},
      art_fulltext: {
        snippet: {
          size: 700,
          fallback: true
        },
      },
      thumbnail_url: {raw: {} },
      tags: {raw: {} },
      art_date_published: {raw: {}}
    },

```

here in the result\_fields I have **art\_fulltext** , so search\_fields object does not work only for this one.  
Do you know why it work in this way?

My guess would be that snippet object works in the way of highlighting the search result in that field.

---

<div class="post-metadata">

### Author: ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)
#### Post date: [January 19, 2022, 9:59pm UTC](https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681/9 "2022-01-19T21:59:21Z")

</div>

I created this sandbox: [search-ui-national-parks-example-search-delete-when-done - CodeSandbox](https://codesandbox.io/s/search-ui-national-parks-example-search-delete-when-done-5jdx2?file=/src/App.js)

If I query for "Chugach", I can see in the API request that the following is set:

```auto
search_fields: {
      title: {},
    },

```

Despite having "Chugach" in the description of the "Wrangell–St. Elias" record, it is still not matched, so it would appear in this case that "search\_fields" IS working.

However, this is an older version of App Search. What version are you on?

EDIT:

I will also point this out...

If you search for "Ranges", in that example it will only match on "Wrangell" from the title field (because "range" is contained in "Wrangell".

However, it will ALSO highlight "Ranges" in the description, even though there was not match on the description.

So to be clear -- **Even if a term is only matched on a single field, ANY field that contains that term will be highlighted. Just because you see a term highlighted does not necessarily indicate that a match occurred on that field**.

 ![wrangell](https://us1.discourse-cdn.com/elastic/original/3X/c/4/c4a58f9b2c879078de8ca6dcfe925535e33791f7.png)

You can see this for yourself if you do a subsequent search on "Chugach", which you can see in the description would be a match, but you will get no results because we're only searching on the title.

---

<div class="post-metadata">

### Author: ![roman.bliztsv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roman.bliztsv/32/100463_2.png) [@roman.bliztsv](https://discuss.elastic.co/u/roman.bliztsv)
#### Post date: [January 20, 2022, 8:51am UTC](https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681/10 "2022-01-20T08:51:54Z")

</div>

Thank you for the explanation & examples, you helped me a lot ! 🙂

---

<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: [February 17, 2022, 8:52am UTC](https://discuss.elastic.co/t/can-we-search-only-by-one-field-f-e-title-description-etc/294681/11 "2022-02-17T08:52:07Z")

</div>

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