5

@を保存したElasticSearchで次のjson構造がありますhttp://localhost:9200/mongoindex/documents/

{
"text" : "OTesting1"
"otag" : "otag1"
"pages" : [{
      "text" : "1"
  "name" : "itag1"

    }, {
     "text" : "2"
     "name" : "itag2"
    }
]
}

ネストされた検索とネストされたフィルターを有効にするために、次のようにネストされたマッピングを作成しました。

http://localhost:9200/mongoindex/documents/_mapping [PUT]

{
  "documents": {
    "properties": {
      "pages": {
        "type": "nested"
      }
    }
  }
}

次のJavaコードで実行されます:

Settings settings = ImmutableSettings.settingsBuilder()
                .put("cluster.name", "xyz").build();
        Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
        SearchResponse response = client.prepareSearch("mongoindex")
                .setTypes("documents")
                .setQuery(QueryBuilders.nestedQuery("documents", QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("pages.text", "1"))).scoreMode("avg"))
                .execute()
                .actionGet();

しかし、それは私に次の例外を与えます:

> Exception in thread "main"
> org.elasticsearch.action.search.SearchPhaseExecutionException: Failed
> to execute phase [query], total failure; shardFailures
> {[kSKaBxjGTMSS352kukrYVw][mongoindex][0]:
> SearchParseException[[mongoindex][0]: from[-1],size[-1]: Parse Failure
> [Failed to parse source
> [{"query":{"nested":{"query":{"bool":{"must":{"match":{"pages.text":{"query":"1","type":"boolean"}}}}},"path":"documents","score_mode":"avg"}}}]]];
> nested: QueryParsingException[[mongoindex] [nested] nested object
> under path [documents] is not of nested type];
> }{[kSKaBxjGTMSS352kukrYVw][mongoindex][4]:
> SearchParseException[[mongoindex][4]: from[-1],size[-1]: Parse Failure
> [Failed to parse source
> [{"query":{"nested":{"query":{"bool":{"must":{"match":{"pages.text":{"query":"1","type":"boolean"}}}}},"path":"documents","score_mode":"avg"}}}]]];
> nested: QueryParsingException[[mongoindex] [nested] nested object
> under path [documents] is not of nested type]; }
4

1 に答える 1

2

この場合、ネストされたクエリでネストされたオブジェクトへのパスを指定する必要があります"path" : "pages"。私はJava構文に精通していませんが、同等のREST要求は次のようになります。

{
   "nested" : {
       "path" : "pages",
       "score_mode" : "avg",
       "query" : {
           "bool" : {
               "must" : [
                   {
                       "match" : {"pages.text" : "1"}
                   }
               ]
           }
       }
   }

}

正直に関連して、ElasticSearchエラーメッセージの最後の行には通常、デバッグする必要のある情報が含まれています(残りはかなり役に立たないか、反復的です)。したがって、これが重要な部分です。

QueryParsingException[[mongoindex][nested]パス[documents]の下のネストされたオブジェクトはネストされたタイプではありません]; }

于 2013-02-27T19:47:07.840 に答える