elastic/elasticsearch

Allow specifying nested fields in queried fields

BlackSlashProd opened this issue · 4 comments

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).

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.

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"]
}
}
}
}
]
}
}
}

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.

Ok ! Now it's clear.

Thanks for your lights @clintongormley !