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

I've created a config using your documentation.

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.

Can someone help me out with this question ?

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

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

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.

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

Great, thanks a lot !

Ping me in here when you will make the sandbox :slight_smile:

Hey, I guess I may found the issue

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.

I created this sandbox: search-ui-national-parks-example-search-delete-when-done - CodeSandbox

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

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.

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.

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

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