如何在Java的Elastic Search 5.4.3中发送JSON查询?

时间:2018-11-06 03:23:52

标签: java elasticsearch

我的索引是

{
    "mappings": {
        "questions" : {
            "properties" : {
                "suggest" : {
                    "type" : "completion",
                    "contexts": [
                        { 
                            "name": "domain",
                            "type": "category",
                            "path": "domain"
                        }
                    ]
                }
            }
        }
    }
}

我的查询看起来像

{
  "suggest": {
      "question-suggest" : {
          "prefix" : "prefix",
          "completion" : {
              "field" : "suggest",
              "size": 100,
              "contexts": {
                "domain": [ 
                  { "context" : "a", "boost" : 1},
                  { "context" : "b", "boost": 4}
                ]
              }
          }
      }
  }
}

这是我要发送的请求,它是上下文提示。

我用过

XContentBuilder query = XContentFactory.jsonBuilder(); client.prepareSearch(esIndexName).setQuery(query);

尽管setQuery()QueryBuilderquery需要XContentBuilder。我也尝试过使用JSON字符串,然后这样做

client.prepareSearch(esIndexName).setQuery(QueryBuilders.wrapperQuery(jsonString))

它给了我; shardFailures {[DS0Y9yhdQceEwlr_X5Bv9g][alldomain-suggester-index][0]: RemoteTransportException[[DS0Y9yh][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: ParsingException[no [query] registered for [question-suggest]]; }{[DS0Y9yhdQceEwlr_X5Bv9g][alldomain-suggester-index][1]: RemoteTransportException[[DS0Y9yh][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: ParsingException[no [query] registered for [question-suggest]]; }{[DS0Y9yhdQceEwlr_X5Bv9g][alldomain-suggester-index][2]: RemoteTransportException[[DS0Y9yh][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: ParsingException[no [query] registered for [question-suggest]]; }{[DS0Y9yhdQceEwlr_X5Bv9g][alldomain-suggester-index][3]: RemoteTransportException[[DS0Y9yh][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: ParsingException[no [query] registered for [question-suggest]]; }{[DS0Y9yhdQceEwlr_X5Bv9g][alldomain-suggester-index][4]: RemoteTransportException[[DS0Y9yh][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: ParsingException[no [query] registered for [question-suggest]]; } 例外

0 个答案:

没有答案