2016-04-14 10 views
3

Ich benutze Elasticsearch v2.3.0. Angenommen, ich habe einen Index mit Mapping:Ist es möglich, den Inhalt des Feldes copy_to in Elasticsearch abzurufen?

{ 
"mappings": { 
    "post": { 
    "dynamic": false, 
    "_source": { 
     "enabled": true 
    }, 
    "properties": { 
     "text": { 
     "norms": { 
      "enabled": false 
     }, 
     "fielddata": { 
      "format": "disabled" 
     }, 
     "analyzer": "text_analyzer", 
     "type": "string" 
     }, 
     "subfield": { 
     "properties": { 
      "subsubfield": { 
      "properties": { 
       "subtext": { 
       "index": "no", 
       "analyzer": "text_analyzer", 
       "type": "string", 
       "copy_to": "text" 
       } 
      } 
      } 
     } 
     } 
    }, 
    "_all": { 
     "enabled": false 
    } 
    } 
} 

Also, Text von subfield.subsubfield.subtext kopiert wird in Text field aufgrund copy_to. Wenn Sie einen Post abfragen, werden nur Daten von text im Feld text angezeigt, da _source nicht geändert wird. Wenn Sie den gesamten Text erhalten möchten, sollten Sie alle Felder auf dem Client aggregieren. Dies kann unbequem sein, wenn viele Unterfelder vorhanden sind.

Gibt es eine magische Abfrage, die es ermöglicht, text Feld mit allen Text kopiert zu bekommen?

+0

I don‘ t denke so, wie die Werte a Re wird in ES internen Datenstrukturen gespeichert (Lucenes invertierte Indizes). Elastic stellt keine APIs zum Anzeigen von Inhalten bereit. – mbudnik

Antwort

5

Im Mapping für text Feld gesetzt "store":"yes" Das sollten Sie es holen können mit fields

Beispiel:

put test/test/_mapping 
{ 
    "properties" : { 
    "name" : { "type" : "string","copy_to": "text"}, 
    "text" : {"type" : "string" ,"store" :"yes"}, 
    "subfield": { 
     "properties": { 
      "subsubfield": { 
      "properties": { 
       "subtext": { 
       "index": "no", 
       "type": "string", 
       "copy_to": "text" 
       } 
      } 
      } 
     } 
     } 
    } 

} 

put test/test/1 
{ 
    "name" : "hello", 
    "subfield" : { 
     "subsubfield" : [ 
      {"subtext" : "soundgarden" }, 
      {"subtext" : "alice in chains" }, 
      {"subtext" : "dio" } 
     ] 
    } 
} 

post test/_search 
{ 
    "fields": [ 
     "text" 
    ] 
} 

Ergebnisse

{ 
    "took": 2, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 1, 
     "max_score": 1, 
     "hits": [ 
     { 
      "_index": "test", 
      "_type": "test", 
      "_id": "1", 
      "_score": 1, 
      "fields": { 
       "text": [ 
        "hello", 
        "soundgarden", 
        "alice in chains", 
        "dio" 
       ] 
      } 
     } 
     ] 
    } 
}