Skip to content

Commit

Permalink
Set get_values defualt size to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
vanatteveldt committed Nov 13, 2023
1 parent 7120c12 commit af30455
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion amcat4/api/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def set_fields(
@app_index.get("/{ix}/fields/{field}/values")
def get_values(ix: str, field: str, _=Depends(authenticated_user)):
"""Get the fields (columns) used in this index."""
return elastic.get_values(ix, field)
return elastic.get_values(ix, field, size=100)


@app_index.get("/{ix}/users")
Expand Down
4 changes: 2 additions & 2 deletions amcat4/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,15 @@ def get_fields(index: Union[str, Sequence[str]]):
return result


def get_values(index: str, field: str) -> List[str]:
def get_values(index: str, field: str, size: int = 100) -> List[str]:
"""
Get the values for a given field (e.g. to populate list of filter values on keyword field)
:param index: The index
:param field: The field name
:return: A list of values
"""
aggs = {"values": {"terms": {"field": field}}}
r = es().search(index=index, size=0, aggs=aggs)
r = es().search(index=index, size=size, aggs=aggs)
return [x["key"] for x in r["aggregations"]["values"]["buckets"]]


Expand Down

0 comments on commit af30455

Please sign in to comment.