3

We have an Elastic Search structure that specifies fields in a multi_match query like this:

"multi_match": {
                            "query": "find this string",
                            "fields": ["*_id^20", "*_name^20", "*"]
                        }

This works great - except under certain circumstances like when query is "Find NOWAK". This is because "NOW" is a reserved word for date searching and field "*" matches fields that are defined as dates.

So what I would like to do is ignore fields that match "*_at".

Is there way to tell Elastic Search to ignore certain fields in a multi_match query?

If the answer to that is "no" then the follow up question is how to escape the search term so that it won't trigger key words

Running version 6.7

ChronoFish
  • 3,589
  • 5
  • 27
  • 38
  • This might help: https://stackoverflow.com/questions/39451688/exclude-a-field-on-a-elasticsearch-query – user7594840 Jul 10 '19 at 21:15
  • @user7594840 The recommend approach in that answer is to explicitly white-list fields. That would be very maintenance intensive for my use-case, The fields list in my documents can grow over time, but only two fields will ever by ignored. – ChronoFish Jul 11 '19 at 13:20

2 Answers2

0

Try this:

Exclude a field on a Elasticsearch query

curl -XGET 'localhost:9200/testidx/items/_search?pretty=true' -d '{
  "query" : {
     "query_string": {
          "fields": ["title", "field2", "field3"],      <-- add this
          "query": "Titulo"
     }},
     "_source" : {
          "exclude" : ["*.body"]
     }
}'
user7594840
  • 103
  • 6
  • this excludes from the `response` not in the search criteria itself. I believe OP is asking to exclude it in the search consideration/context itself. – JBone Jul 11 '19 at 00:10
  • Not sure I understand, but maybe using bool -> “must not” could work – user7594840 Jul 11 '19 at 04:08
  • @JBone is correct. I'm trying to prevent certain fields from being searched (really trying to avoid fields of a certain type). The code snippet above white-list fields, I want to know if I can black-list them. thanks – ChronoFish Jul 11 '19 at 13:08
  • 1
    @user7594840 bool->"must not" would search the field and then remove the document from the return list. I want to avoid searching the field all together. This is because some of my fields are defined as type "date" and my query string will cause Elastic Search to return an error if it's included in the search – ChronoFish Jul 11 '19 at 13:13
  • @JBone I see. I researched a little more and found this https://stackoverflow.com/questions/52757277/how-to-exclude-a-field-from-getting-searched-by-elasticsearch-6-1 - seems to specifically ask for a solution that doesn't simply whitelist – user7594840 Jul 11 '19 at 15:13
0

Apparently the answer is "No: there is not a way to tell ElasticSearch to ignore certain fields in a multi_match query"

For my particular issue I found an inexpensive way to find the necessary white-listed fields (this is performed outside the scope of ElasticSearch otherwise I would post it here) and list those in place of the "*" when building the query.

I am hopeful someone will tell me I'm wrong, but I don't think I am.

ChronoFish
  • 3,589
  • 5
  • 27
  • 38