问题
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.
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.
Can I do this?
回答1:
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
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
}
}
}
}
}
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
来源:https://stackoverflow.com/questions/38980506/elasticsearch-field-filterable-but-not-searchable