我正在尝试执行以下查询:
{
"query": {
"bool": {
"must": [
{
"term": {
"Thing.Name": {
"value": "(item) test",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
}
这没有产生结果,我也不知道为什么。我有父母和一个空间。我在这里有什么选择?
答案 0 :(得分:1)
您要匹配使用术语查询的确切值。正如阿米特(Amit)在评论中所提到的,术语查询不使用分析器,因此它将与包含完全相同的标记的文档匹配,您需要按以下方式修改Thing.Name的映射:
{
"Thing": {
"properties": {
"Name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
如果映射是由Elastic自动生成的,则其名称字段将具有与上述相似的属性。如果已经存在,则无需在映射中进行任何修改。更新查询以使用Thing.Name.keyword
而不是Thing.Name
,因为类型keyword
的字段不会分析该值并生成单个令牌,该令牌本身就是输入值。
因此查询将是:
{
"query": {
"bool": {
"must": [
{
"term": {
"Thing.Name.keyword": {
"value": "(item) test",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
}