Skip to content

Nested Filter does not allow .Filter only filter #880

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

Closed
Philo opened this issue Aug 14, 2014 · 4 comments
Closed

Nested Filter does not allow .Filter only filter #880

Philo opened this issue Aug 14, 2014 · 4 comments

Comments

@Philo
Copy link
Contributor

Philo commented Aug 14, 2014

The below query should be supported by NEST, however it results in a conditionless filter being produced.

                Filter<Document>.Nested(n => n
                    .Path("nested_property")
                    .Filter(f => f
                        .Term("nested_property.path", "myvalue")
                    )
                    );
    "filter": {
        "nested": {
           "path": "nested_property",
           "filter" : {
               "term": {
                  "nested_property.path": "myvalue"
               }
        }
    }
}

A workaround is to ensure that you include a .Query(q => q.MatchAll()) within your nested filter.

@Philo
Copy link
Contributor Author

Philo commented Aug 14, 2014

I will submit a fix via pull request shortly

Philo added a commit to Philo/elasticsearch-net that referenced this issue Aug 14, 2014
…lter does not result in a conditionless NEST filter (leading to its exclusion from generated json query)
@jayhilden
Copy link

I can confirm that the issue exists, and I can also confirm the workaround of adding ".Query(q => q.MatchAll())"

Here is my non-working search:

        var result = ElasticClient.Search<PackingContainerES>(s =>
            s.Filter(f =>
                f.Or(or => or.Term(t1 => t1.ContainerID, containerID.Value),
                    or2 => or2.Nested(nest =>
                        nest
                            .Path(p => p.InnerContainers)
                            .Filter(nf => nf.Term("innerContainers.containerID", containerID.Value))
                        )
                    )
                )
            );

Here is the working:

        var result = ElasticClient.Search<PackingContainerES>(s =>
            s.Filter(f =>
                f.Or(or => or.Term(t1 => t1.ContainerID, containerID.Value),
                    or2 => or2.Nested(nest =>
                        nest
                            .Query(q => q.MatchAll())
                            .Path(p => p.InnerContainers)
                            .Filter(nf => nf.Term("innerContainers.containerID", containerID.Value))
                        )
                    )
                )
            );

@gmarz
Copy link
Contributor

gmarz commented Aug 19, 2014

Thanks for confirming @jayhilden. #881 will fix this, just waiting for the CLA so I can merge it in.

gmarz added a commit that referenced this issue Aug 19, 2014
re #880 - Ensures that a nested filter consisting of only a filter does ...
@gmarz
Copy link
Contributor

gmarz commented Aug 20, 2014

Closed by #881

@gmarz gmarz closed this as completed Aug 20, 2014
Tasteful pushed a commit to Tasteful/elasticsearch-net that referenced this issue Aug 26, 2014
…lter does not result in a conditionless NEST filter (leading to its exclusion from generated json query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants