【问题标题】:Unable to find a field mapper for field in nested query using field_value_factor无法使用 field_value_factor 为嵌套查询中的字段找到字段映射器
【发布时间】:2015-08-14 21:35:14
【问题描述】:

这是映射:

PUT books-index
{
  "mappings": {
    "books": {
      "properties": {
        "tags": {
          "type": "nested",
          "fields": {
            "name": {
              "type": "string"
            },
            "weight": {
              "type": "float"
            }
          }
        }
      }
    }
  }
}

然后使用 field_value_factor 执行嵌套查询失败并出现错误

GET books-index/books/_search
{
  "query": {
    "nested": {
      "path": "tags",
      "score_mode": "sum",
      "query": {
        "function_score": {
          "query": {
            "match": {
              "tags.name": "world"
            }
          },
        "field_value_factor": {
            "field": "weight"
         }
        }
      }
    }
  }
}

错误:"nested: ElasticsearchException[Unable to find a field mapper for field [weight]]"

有趣的是,如果索引中有一本书带有标签 - 没有错误并且查询运行良好。

为什么会这样?索引中没有带有标签的书籍时,如何防止错误?

有什么想法吗?

谢谢!

附: github上也有一个问题:https://github.com/elastic/elasticsearch/issues/12871

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您的映射似乎不正确。

    PUTing你提供的映射后,尝试执行GET books-index/_mapping,它会显示这些结果:

    "books-index": {
      "mappings": {
         "books": {
            "properties": {
               "tags": {
                  "type": "nested"
               }
            }
         }
      }
    }
    

    缺少名称和重量!映射的问题是您使用了fields 而不是properties,或者您忘记输入第二个properties 键。

    我修改了您的映射以反映您在标签中寻找嵌套名称和类型,因为看起来这就是您的查询想要的。

    PUT books-index
    {
      "mappings": {
        "books": {
          "properties": {
            "tags": {
              "type": "nested",
              "properties": {               // <--- HERE!
                "name": {
                  "type": "string"
                },
                "weight": {
                  "type": "float"
                }
              }
            }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      • 2020-09-01
      • 1970-01-01
      相关资源
      最近更新 更多