Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example with search query match before aggregate #96

Open
robomotic opened this issue Sep 21, 2021 · 4 comments
Open

add example with search query match before aggregate #96

robomotic opened this issue Sep 21, 2021 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@robomotic
Copy link

robomotic commented Sep 21, 2021

Hi there,
I am struggling to make a simple match query via the Search class.
This is okay:


filebeat = indices['filebeat-7.14.0-2021.08.24-000001']
search = filebeat.search().size(1).groupby('alerts_day', 'date_histogram', fixed_interval='1d', field='@timestamp',format="yyyy-MM-dd")

search.to_dict()

But I only want to filter to a subset.

filebeat = indices['filebeat-7.14.0-2021.08.24-000001']
q = {'query': {'match': {'log.file.path':'first-org-conf-2015-eve.json'}}}
search = filebeat.search().filter('term',log.file.path='first-org-conf-2015-eve.json').size(1).groupby('alerts_day', 'date_histogram', fixed_interval='1d', field='@timestamp',format="yyyy-MM-dd")

search.to_dict()

This generates an error.

Where do I add the match syntax? Should I do via filter but how?

@alk-lbinet
Copy link
Contributor

Hi @robomotic,
The error is caused by filter('term', log.file.path='xxx') since python doesn't accept dots '.' in functions named keywords (ie you can do some_thing="xxx" but not some.thing="xxx").

Here are the workarounds:

# replace '.' by '__', it will be automatically converted in '.'
.filter('term', log__file__path='first-org-conf-2015-eve.json')

# use the "native" query syntax
.filter('term', {"log.file.path": 'first-org-conf-2015-eve.json'})

# use the pandagg query classes
from pandagg.query import Term
.filter(Term(field="log.file.path", value='first-org-conf-2015-eve.json'))

cheers
Léonard

@alk-lbinet alk-lbinet added the documentation Improvements or additions to documentation label Sep 22, 2021
@alk-lbinet
Copy link
Contributor

I leave the issue open until documentation is clear on this point (main focus in the coming month).

@priamai
Copy link

priamai commented Sep 22, 2021

That worked and yes would love to have a better documentation!
Also would be nice to show how to iterate through an index

indices = discover(es_client, "filebeat-*")
for index in indices: ???

It is not an iterable so some example is required.

@alk-lbinet
Copy link
Contributor

@priamai can you create a dedicated issue for that thx :) (feature request)

@leonardbinet leonardbinet added this to the Solid documentation milestone Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Development

No branches or pull requests

4 participants