Elasticsearch Prefix query not working on nested documents -
i'm using prefix query elasticsearch query. works fine when using on top-level data, once applied nested data there no results returned. data try query looks follows:
here prefix query works fine: query:
{ "query": { "prefix" : { "duration": "7"} } }
result:
{ "took": 25, ... }, "hits": { "total": 6, "max_score": 1, "hits": [ { "_index": "itemresults", "_type": "itemresult", "_id": "item_result_7c8649c2-6cb0-487e-bb3c-c4bf0ad28a90_8bce0a3f-f951-4a01-94b5-b55dea1a2752_7c965241-ad0a-4a83-a400-0be84daab0a9_61", "_score": 1, "_source": { "score": 1, "studentid": "61", "timestamp": 1377399320017, "groupidentifiers": {}, "assessmentitemid": "7c965241-ad0a-4a83-a400-0be84daab0a9", "answered": true, "duration": "7.078", "metadata": { "korrektur": "a", "matrize12_13": "ma.1.b.1.d.1", "kompetenz": "zuv", "zyklus": "z2", "schwierigkeit": "h", "handlungsaspekt": "aue", "fach": "ma", "aufgabentyp": "l" }, "assessmentsessionid": "7c8649c2-6cb0-487e-bb3c-c4bf0ad28a90", "assessmentid": "8bce0a3f-f951-4a01-94b5-b55dea1a2752" } },
now trying use prefix query apply on nested structure 'metadata' doesn't return result:
{ "query": { "prefix" : { "metadata.fach": "m"} } }
result:
{ "took": 18, "timed_out": false, "_shards": { "total": 15, "successful": 15, "failed": 0 }, "hits": { "total": 0, "max_score": null, "hits": [] } }
what doing wrong? @ possible apply prefix on nested data?
it not depends whether nested or not. depends on mapping, if analyzing string @ index time or not.
i'm going put example:
i've created , index following mapping:
curl -xput 'http://localhost:9200/test/' -d ' { "mappings": { "test" : { "properties" : { "text_1" : { "type" : "string", "index" : "analyzed" }, "text_2" : { "index": "not_analyzed", "type" : "string" } } } } }'
basically 2 text fields, 1 analyzed , other not_analyzed. index following document:
curl -xput 'http://localhost:9200/test/test/1' -d ' { "text_1" : "hello world", "text_2" : "hello world" }'
text_1 query
as text_1 analyzed 1 of things elasticsearch convert field lower case. if make following query doesn't find document:
curl -xget 'http://localhost:9200/test/test/_search?pretty=true' -d ' { "query": { "prefix" : { "text_1": "h"} } } ' { "took" : 2, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 0, "max_score" : null, "hits" : [ ] } }
but if trick , use lower case making query:
curl -xget 'http://localhost:9200/test/test/_search?pretty=true' -d ' { "query": { "prefix" : { "text_1": "h"} } } ' { "took" : 2, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "test", "_type" : "test", "_id" : "1", "_score" : 1.0, "_source" : { "text_1" : "hello world", "text_2" : "hello world" } } ] } }
text_2 query
as text_2 not analyzed, when make original query matches:
curl -xget 'http://localhost:9200/test/test/_search?pretty=true' -d ' { "query": { "prefix" : { "text_2": "h"} } } ' { "took" : 1, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "test", "_type" : "test", "_id" : "1", "_score" : 1.0, "_source" : { "text_1" : "hello world", "text_2" : "hello world" } } ] } }
Comments
Post a Comment