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

Allow specifying nested fields in queried fields #9611

Closed
BlackSlashProd opened this issue Feb 9, 2015 · 4 comments
Closed

Allow specifying nested fields in queried fields #9611

BlackSlashProd opened this issue Feb 9, 2015 · 4 comments

Comments

@BlackSlashProd
Copy link

Hello, I'm a French developper. I work with ElasticSearch 1.4.2.

I find a bug (maybe) that is much the same as this : #5110

I need to specify nested fields in "fields" parameter of query string (query_string and simple_query_string). I try a lot of synthax but nothing work fine.

Steps to reproduce : https://github.com/BlackSlashProd/UploadZone/blob/master/ElasticSearch/Nested_Fields_Bug_Reproduce.txt
Query 1 and 2 are OK. Query 3 and 4 show the bug.

As you can see the problem appears when i specify the queried fields.
Even if i try "fields" : ["message","comments","comments_name","comments_comment"].

It's a bad use ? It's a bug ? it's the same bug as #5110 ?

(Sorry for my broken English).

@clintongormley
Copy link
Contributor

Hi @BlackSlashProd

Nested fields are not support in query_string/simple_query string. The issue you link to refers to nested fields, but the terminology is incorrect. Really it is talking about ordinary object or multi-fields, not real nested fields.

Nested fields need to be queries with nested queries/filters, because multiple documents can match and you need to be able to specify how these multiple scores should be reduced to a single score.

@BlackSlashProd
Copy link
Author

Ok thanks @clintongormley.

I think I understand the cause.

But I ask me "Why when you don't specify the queried fields, ES search in nested fields ?"

curl -XPOST 'http://localhost:9200/test/tweet/_search' -d '{
"query": {
"simple_query_string": {
"query": "Hello"
}
}}'

So as I have to do something like that ?
curl -XPOST 'http://localhost:9200/test/tweet/_search' -d '{
"query" : {
"bool" : {
"should" : [
{
"simple_query_string": {
"query": "Hello",
"fields" : ["message"]
}
},
{
"nested": {
"path": "comments",
"query": {
"multi_match": {
"query": "Hello",
"fields": ["name","comment"]
}
}
}
}
]
}
}
}

@clintongormley
Copy link
Contributor

When you don't specify a field, you are actually querying the single catch-all _all field, not each field separately. And yes, your example query looks fine.

@BlackSlashProd
Copy link
Author

Ok ! Now it's clear.

Thanks for your lights @clintongormley !

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

2 participants