elasticsearch-可过滤但不可搜索的字段 [英] elasticsearch - field filterable but not searchable
问题描述
使用弹性2.3.5.有没有一种方法可以使字段可过滤但不可搜索?例如,我有一个 language
字段,其值类似于 en-US
.在 query-> bool-> filter-> term
中设置几个过滤器,我可以过滤结果集而不会影响分数,例如,仅搜索具有在
.语言
字段中> zh-CN
Using elastic 2.3.5. Is there a way to make a field filterable, but not searchable? For example, I have a language
field, with values like en-US
. Setting several filters in query->bool->filter->term
, I'm able to filter the result set without affecting the score, for example, searching for only documents that have en-US
in the language
field.
但是,我希望查询词 en-US
的查询不返回任何结果,因为这实际上不是要搜索的索引字段,但是我可以进行过滤.
However, I want a query searching for the term en-US
to return no results, since this is not really an indexed field for searching, but just so I can filter.
我可以这样做吗?
推荐答案
ElasticSearch使用_all字段来允许对整个文档进行快速的全文本搜索.这就是为什么在所有文档的所有字段中搜索en-US都会为您返回一个包含'language':'en-US'的原因. https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html
ElasticSearch use an _all field to allow fast full-text search on entire documents. This is why searching for en-US in all fields of all documents return you the one containing 'language':'en-US'. https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html
您可以在映射中指定"include_in_all":false
,以停用将字段包含到_all的功能.
You can specify "include_in_all": false
in the mapping to deactivate include of a field into _all.
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"title": {
"type": "string"
},
"country": {
"type": "string"
},
"language": {
"type": "string",
"include_in_all": false
}
}
}
}
}
在此示例中,在所有字段中搜索"US"将仅返回标题或国家/地区中包含US的文档.但是您仍然可以使用language字段过滤查询. https://www.elastic.co/guide/en/elasticsearch/reference/current/include-in-all.html
In this example, searching for 'US' in all field will return only document containing US in title or country. But you still be able to filter your query using the language field. https://www.elastic.co/guide/en/elasticsearch/reference/current/include-in-all.html
这篇关于elasticsearch-可过滤但不可搜索的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!