Nested query error


(Madhur Bhardwaj) #1

Hi,

I am new to elasticsearch and currently working with nested objects and query...
I am able to create a nested object but when trying to query it using nested query syntax getting error in field name ... the error says "Field name XXX cannot contain '.' "
not sure how I can refer a nested object field name in query without "Dot"

also getting error in elasticSearch.Net ... when trying to execute query it gives error...
"[nested] nested object under path [XXX] is not of nested type" ...
But I can see it on the nested object is marked as nested in index/type...

Followed this link also ... but same error...


(Xavier Facq) #2

Hi,

1°/ Can you provide the Elasticsearch version you are using ?

2°/ Are you certain that your index "bands" is realy created with the mapping (the query seems ok so...) ?


(Madhur Bhardwaj) #3

Am using version 2.4.1 ... elasticsearch.net
yes i checked it... it was created successfully .. i followed the instruction given in the link..

Thanks,
Madhur


(Xavier Facq) #4

You may have other indices without the same mapping, change query URLS to only search into your /band index:

curl -XGET "http://172.16.50.12:9200/bands/_search?pretty=true" -d '
{
    "query" : {
        "nested" : {
            "path" : "xref",
            "query" : {
                "bool" : {
                    "must" : [
                        { "match" : { "xref.name" : "Roger" } }
                    ]
                }
            }
        }
    },
    "fields" : [
        "title"
    ]
}'

(Madhur Bhardwaj) #5

It is saying
Field name [xref.name] cannot contain '.'

again same error..

Madhur


(Xavier Facq) #6

Can you provide result of :

curl 'http://localhost:9200/bands/_mapping?pretty'

(Madhur Bhardwaj) #7

{
"bands": {
"mappings": {
"documents": {
"properties": {
"fields": {
"type": "string"
}-
"query": {
"properties": {
"nested": {
"properties": {
"path": {
"type": "string"
}-
"query": {
"properties": {
"bool": {
"properties": {
"must": {
"properties": {
"match": {
"properties": {
"name": {
"type": "string"
}-
"xref_name": {
"type": "string"
}-
}-
}-
}-
}-
}-
}-
}-
}-
}-
}-
}-
}-
"title": {
"type": "string"
}-
"xref": {
"type": "nested"
"properties": {
"name": {
"type": "string"
}-
}-
}-
"year": {
"type": "integer"
}-
}-
}-
}-
}-
}


(Xavier Facq) #8

Can you provide a clean JSON of:

curl 'http://localhost:9200/bands/_mapping?pretty' 

curl 'http://localhost:9200/bands/documents/_mapping?pretty'

(Madhur Bhardwaj) #9

curl 'http://localhost:9200/bands/_mapping?pretty'

{
"bands": {
"mappings": {
"documents": {
"properties": {
"fields": {
"type": "string"
},
"query": {
"properties": {
"nested": {
"properties": {
"path": {
"type": "string"
},
"query": {
"properties": {
"bool": {
"properties": {
"must": {
"properties": {
"match": {
"properties": {
"name": {
"type": "string"
},
"xref_name": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
},
"title": {
"type": "string"
},
"xref": {
"type": "nested",
"properties": {
"name": {
"type": "string"
}
}
},
"year": {
"type": "integer"
}
}
}
}
}
}


(Madhur Bhardwaj) #10

curl 'http://localhost:9200/bands/documents/_mapping?pretty'

{
"bands": {
"mappings": {
"documents": {
"properties": {
"fields": {
"type": "string"
},
"query": {
"properties": {
"nested": {
"properties": {
"path": {
"type": "string"
},
"query": {
"properties": {
"bool": {
"properties": {
"must": {
"properties": {
"match": {
"properties": {
"name": {
"type": "string"
},
"xref_name": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
},
"title": {
"type": "string"
},
"xref": {
"type": "nested",
"properties": {
"name": {
"type": "string"
}
}
},
"year": {
"type": "integer"
}
}
}
}
}
}


(Xavier Facq) #11

Your mappings are very strange, I don't understand why you have code looking like queries... I suggest to drop your indices and restart the tutorial from the beginning...


(Madhur Bhardwaj) #12

As suggested I re-created indices , but no luck ... same error...
just want to know why this is showing error message regarding "." dot in nested query...
could you please let me know how I can refer nested object property without using Dot "."...


(Xavier Facq) #13

Running this minimal script on a 2.2.0 server : http://pastebin.com/yzLE1DDc
Works perfectly.

You have too refer with a Dot into the name.

@See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html


(Madhur Bhardwaj) #14

This is the error I am getting..

{
"error": {
"root_cause": [1]
0: {
"type": "mapper_parsing_exception"
"reason": "Field name [xref.name] cannot contain '.'"
}-

"type": "mapper_parsing_exception"
"reason": "Field name [xref.name] cannot contain '.'"
}-
"status": 400
}


(Madhur Bhardwaj) #15

Here is the version info of elastic search...

{
"name": "Angela Del Toro"
"cluster_name": "elasticsearch"
"cluster_uuid": "xwJsk3DUT--w9X6le_BIww"
"version": {
"number": "2.4.1"
"build_hash": "c67dc32e24162035d18d6fe1e952c4cbcbe79d16"
"build_timestamp": "2016-09-27T18:57:55Z"
"build_snapshot": false
"lucene_version": "5.5.2"
}-
"tagline": "You Know, for Search"
}


(Xavier Facq) #16

Sorry, but I have no more idea...

@dadoonet @warkolm : a suggestion why his nested queries fail on this version ?


(Madhur Bhardwaj) #17

No issue...

one more quick quick question... is it possible to get raw query generated by elasticSearch.Net library ... "Nest"...
Am able to get result using rest client but when executing same from Nest getting some error
"[nested] failed to find nested object under path" ...
using following code to fire query...

var response = client.Search(s => s.Index("contractindex").Query(q =>q.Nested(c => c.Path(p => p.Limits)
.Query(nq => nq.Bool(bl => bl.Must(mst => mst
.Match(t => t.Field( fld => fld.Limits.First().LimitType).
Query("Limit"))))
))));


(Xavier Facq) #18

It works when you run the query with Curl command ?

If yes, the problem is in your .Net code... I don't know .Net, but I don't see the pathname in your code.


(system) #19