You need to use multi-fields if you want to map the title
field as text
and keyword
type. Modify your index mapping to
{
"mappings": {
"properties": {
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
Index Data:
{
"title": "Software and Data Quality Manager"
}
{
"title": "Software Engineer"
}
{
"title": "Engineer"
}
Search Query:
{
"from": 0,
"size": 20,
"query": {
"bool": {
"must_not": {
"term": {
"title.keyword": "Software Engineer"
}
}
}
}
}
Search Result:
"hits": [
{
"_index": "66064654",
"_type": "_doc",
"_id": "2",
"_score": 0.0,
"_source": {
"title": "Engineer"
}
},
{
"_index": "66064654",
"_type": "_doc",
"_id": "3",
"_score": 0.0,
"_source": {
"title": "Software and Data Quality Manager"
}
}
]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…