如何解决ElasticSearch中这个json的错误?

ybzsozfc  于 2023-01-25  发布在  ElasticSearch
关注(0)|答案(1)|浏览(218)

我需要计算员工最共同的利益
它的json类似于:

{"index":{"_index":"companydatabase"}}  
 {"FirstName":"ELVA","LastName":"RECHKEMMER","Designation":"CEO","Salary":"154000","DateOfJoining":"1993-01-11","Address":"8417 Blue Spring St. Port Orange, FL 32127","Gender":"Female","Age":62,"MaritalStatus":"Unmarried","Interests":["Body Building","Illusion","Protesting","Taxidermy","TV watching","Cartooning","Skateboarding"]}
{"index":{"_index":"companydatabase"}}  
 {"FirstName":"JENNEFER","LastName":"WENIG","Designation":"President","Salary":"110000","DateOfJoining":"2013-02-07","Address":"16 Manor Station Court Huntsville, AL 35803","Gender":"Female","Age":45,"MaritalStatus":"Unmarried","Interests":["String Figures","Working on cars","Button Collecting","Surf Fishing"]}
{"index":{"_index":"companydatabase"}}

我写道:

request_body = {
  "size": 0,
  "aggs": {
    "interests": {
      "terms": {
        "field": "Interests",
        "size": 10,
        "order": {
          "count": "desc"
        }
      }
    }
  }
}
JSON(es.search(index="companydatabase", body=request_body))

但朱庇特的笔记本给我回了个错误

RequestError: RequestError(400, 'search_phase_execution_exception', 'Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [Interests] in order to load field data by uninverting the inverted index. Note that this can use significant memory.')

最后一行中的错误
谢谢你帮我

t5fffqht

t5fffqht1#

看起来你正在使用默认Map为您的Elasticsearch索引即(Elasticsearch生成的Map为您的索引),
并且您正在使用默认情况下不支持的text字段上的terms聚合,您可以使用

request_body = {
  "size": 0,
  "aggs": {
    "interests": {
      "terms": {
        "field": "Interests.keyword", --> note here
        "size": 10
      }
    }
  }
}

如果您的Map是由Elasticsearch生成的,它应该可以工作。
有关详细信息,请参阅https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html和。

相关问题