2012-08-08 12 views
18

Używam proste zapytanie tak:Nie więcej _source jeśli script_fields jest stosowany w elasticsearch zapytania

{ 
    "query": { 
    "term": { 
     "statuses": "active" 
    } 
    }, 
    "script_fields": { 
    "test": { 
     "script": "_source.name" 
    } 
    } 
} 

Problem polega na tym, że gdy wprowadzam script_fields, już nie dostać _source w moich wynikach.

Próbowałem:

{ 
    "fields": [ 
    "_all" 
    ], 
    "query": { 
    "term": { 
     "statuses": "active" 
    } 
    }, 
    "script_fields": { 
    "email": { 
     "script": "_source.name" 
    } 
    } 
} 

i

{ 
    "fields": [ 
    "*" 
    ], 
    "query": { 
    "term": { 
     "statuses": "active" 
    } 
    }, 
    "script_fields": { 
    "email": { 
     "script": "_source.name" 
    } 
    } 
} 

Ale nie robi żadnej różnicy. Czy istnieje sposób na odzyskanie _source oprócz script_fields?

Odpowiedz

20

W tablicy fields, uczynić go załadować _source:

{ 
    "fields": [ 
    "_source" 
    ], 
    "query": { 
    "term": { 
     "statuses": "active" 
    } 
    }, 
    "script_fields": { 
    "email": { 
     "script": "_source.name" 
    } 
    } 
} 
+0

Czy ktoś wie dokładnie _why_ tak się dzieje? Czy jest to związane z https://github.com/elastic/elasticsearch/issues/20068? –

0

Działa to dla mnie:

curl -X DELETE localhost:9200/a 

curl -X POST localhost:9200/a/b/c -d '{"title" : "foo"}' 

curl -X POST localhost:9200/a/_refresh 

echo; 

curl localhost:9200/a/_search?pretty -d '{ 
    "fields": [ 
    "_source" 
    ], 
    "query": { 
    "match_all": {} 
    }, 
    "script_fields": { 
    "title_script": { 
     "script": "_source.title" 
    } 
    } 
}' 

wyjściowa:

"hits" : { 
    # ... 
    "hits" : [ { 
    # ... 
    "_source" : {"title" : "foo"}, 
    "fields" : { 
     "title_script" : "foo" 
    } 
    } ] 
} 
Powiązane problemy