ElasticSearch:使用JEST插入带有_parent字段的元素

des*_*iny 2 elasticsearch jest

我正在为应用程序使用ElasticSearch来存储和搜索数据.因为在我的特定情况下搜索关系也很重要,所以我最近改变了数据的结构,现在我正在使用_parent字段.(http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-parent-field.html)

我已经设计了搜索查询,它完全正常.但是,我在数据库中插入新的子条目时遇到问题.

它应该这样工作:


没有_parent字段,当我想实现这一目标时

$ curl -XPUT 'http://localhost:9200/data/child/1' -d '
Run Code Online (Sandbox Code Playgroud)

我使用JEST API以这种方式插入数据:

client.execute(new Index.Builder(payload).index("data").type("child").build());
Run Code Online (Sandbox Code Playgroud)

当我想实现这个目标时:

$ curl -XPOST localhost:9200/data/child?parent=154121-d'
Run Code Online (Sandbox Code Playgroud)

我应该如何使用JEST-API实现这一点?


我已经在Google // Stackoverflow上搜索了一个答案,但没有提出解决方案.

先感谢您!:)

des*_*iny 13

我终于找到了解决方案!:)

可以为请求提供参数.实现此目的的正确代码行:

$ curl -XPOST localhost:9200/data/child?parent=154121-d'
Run Code Online (Sandbox Code Playgroud)

将通过以下方式实现:

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

希望将来可以帮助这个答案!:)