Elasticsearch-dsl-py: How to implement a count like _count in elasticsearch with elasticsearch_dsl over python

Created on 14 Aug 2015  路  2Comments  路  Source: elastic/elasticsearch-dsl-py

How I can do a query to count all parameters from an index accoding to a specific query. I want to say I do not know do this query with elastichsearch_dsl:

GET my_index/my_type/_count
{
"query": {
"match_all": {}
}
}

for example we have as result this:

{
"count": 2472,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
}
}

Thanks in advance

Most helpful comment

there is a count method to do this, it returns the number of matching docs:

from elasticsearch_dsl import Search
s = Seacrh(index='my_index', doc_type='my_type')
s = s.query(...)
print(s.count())

Hope this helps.

All 2 comments

there is a count method to do this, it returns the number of matching docs:

from elasticsearch_dsl import Search
s = Seacrh(index='my_index', doc_type='my_type')
s = s.query(...)
print(s.count())

Hope this helps.

hello
petite question .
je suis tous nouveau sur ES et python et j'ai vraiment du mal avec si quelqun pourrait m'aider ca serai cool.
j'aimerai faire un script python qui va checker sur ES a l'aide d'une requette : le nombre d'IP differente, nombre de user different et le nombre de machine differente tri茅 par nom puis apres identifi茅 les machines sur lesquelle un compte s'est connecte avec un tri sur le timestamp.

est'il possible de le faire en realite ?
si oui possible d'avoir quelque piste svp?

actuellement je bloque a ce stade:

from elasticsearch import Elasticsearch
es = Elasticsearch(['localhost:9200'])
res = es.search(
index='test-*',
body={
"query": {
"match": {
"message": " "
}
}
print(res)
)

merci d'avance

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zahir-koradia picture zahir-koradia  路  3Comments

beanaroo picture beanaroo  路  4Comments

njoannin picture njoannin  路  3Comments

vmogilev picture vmogilev  路  4Comments

mortada picture mortada  路  3Comments