2014-10-17 53 views
2

我爲應用程序使用ElasticSearch來存儲和搜索數據。 因爲在我的特定情況下搜索關係也很重要,所以我最近更改了數據的結構,現在我正在使用_parent字段。 (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-parent-field.htmlElasticSearch:使用JEST插入具有_parent字段的元素

我已經設計了搜索查詢,它工作得很好。但是,在我的數據庫中插入新的子項時,我現在遇到了問題。

它應該是這樣的:


沒有_parent場,當我想實現這個

$ curl -XPUT 'http://localhost:9200/data/child/1' -d ' 

我插入的數據使用JEST API是這樣的:

client.execute(new Index.Builder(payload).index("data").type("child").build()); 

W母雞我想實現這一點:

$ curl -XPOST localhost:9200/data/child?parent=154121-d' 

我該如何使用JEST-API實現這個功能?


我已經在Google // Stackoverflow上搜尋了一個答案,但沒有拿出解決方案。

預先感謝您! :)

回答

11

我終於找到了解決方案! :)

可以爲請求提供一個參數。正確的代碼行來實現這一目標:

$ curl -XPOST localhost:9200/data/child?parent=154121-d' 

將與實現這一目標:

client.execute(new Index.Builder(payload).index("data").type("child").setParameter("parent", "154121").build()); 

希望我能幫助別人這個答案在未來! :)

+1

你沒有:)謝謝 – Lorenzo 2015-07-17 13:39:31