2012-08-08 5 views
18

Ich bin eine einfache Abfrage wie so ausgeführt wird:nicht mehr _Source wenn script_fields in Elasticsearch Abfrage verwendet wird

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

Das Problem ist, dass wenn ich die script_fields vorstellen, ich nicht mehr _source in meinen Ergebnissen.

Ich habe versucht:

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

und

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

Aber sie haben keinen Unterschied machen. Gibt es eine Möglichkeit, _source zusätzlich zum script_fields zurückgegeben werden?

Antwort

20

Im fields Array, machen es _source laden:

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

jemand genau Kennt _why_ dies geschieht? Hat es mit https://github.com/elastic/elasticsearch/issues/20068 zu tun? –

0

Dies funktioniert für mich:

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

Ausgang:

"hits" : { 
    # ... 
    "hits" : [ { 
    # ... 
    "_source" : {"title" : "foo"}, 
    "fields" : { 
     "title_script" : "foo" 
    } 
    } ] 
} 
Verwandte Themen