4

Elasticsearch クエリにプレフィックスクエリを使用しています。トップレベルのデータで使用すると問題なく動作しますが、ネストされたデータに適用すると結果が返されません。クエリしようとするデータは次のようになります。

ここでは、プレフィックスクエリが正常に機能します。クエリ:

{ "query": { "prefix" : { "duration": "7"} } }

結果:

{
   "took": 25, ... },
   "hits": {
      "total": 6,
      "max_score": 1,
      "hits": [
         {
        "_index": "itemresults",
        "_type": "itemresult",
        "_id": "ITEM_RESULT_7c8649c2-6cb0-487e-bb3c-c4bf0ad28a90_8bce0a3f-f951-4a01-94b5-b55dea1a2752_7c965241-ad0a-4a83-a400-0be84daab0a9_61",
        "_score": 1,
        "_source": {
           "score": 1,
           "studentId": "61",
           "timestamp": 1377399320017,
           "groupIdentifiers": {},
           "assessmentItemId": "7c965241-ad0a-4a83-a400-0be84daab0a9",
           "answered": true,
           "duration": "7.078",
           "metadata": {
              "Korrektur": "a",
              "Matrize12_13": "MA.1.B.1.d.1",
              "Kompetenz": "ZuV",
              "Zyklus": "Z2",
              "Schwierigkeit": "H",
              "Handlungsaspekt": "AuE",
              "Fach": "MA",
              "Aufgabentyp": "L"
           },
           "assessmentSessionId": "7c8649c2-6cb0-487e-bb3c-c4bf0ad28a90",
           "assessmentId": "8bce0a3f-f951-4a01-94b5-b55dea1a2752"
        }
     },

プレフィックスクエリを使用して、ネストされた構造 'metadata' に適用しようとしても、結果が返されません。

{ "query": { "prefix" : { "metadata.Fach": "M"} } }

結果:

{
   "took": 18,
   "timed_out": false,
   "_shards": {
      "total": 15,
      "successful": 15,
      "failed": 0
   },
   "hits": {
      "total": 0,
      "max_score": null,
      "hits": []
   }
}

私は何を間違っていますか?ネストされたデータにプレフィックスを適用することはまったく可能ですか?

4

1 に答える 1

8

ネストされているかどうかには依存しません。インデックス時に文字列を分析しているかどうかは、マッピングによって異なります。

例を挙げます:

次のマッピングを使用して作成し、インデックスを作成しました。

curl -XPUT 'http://localhost:9200/test/' -d '
{
  "mappings": {

    "test" : {
      "properties" : {
        "text_1" : {
           "type" : "string",
           "index" : "analyzed"
        },
        "text_2" : {
          "index": "not_analyzed",
           "type" : "string"
        }
      }
    }
  }
}'

基本的に 2 つのテキスト フィールド、1 つは分析済み、もう 1 つは未分析です。ここで、次のドキュメントにインデックスを付けます。

curl -XPUT 'http://localhost:9200/test/test/1' -d '
{
"text_1" : "Hello world",
"text_2" : "Hello world"
}'

text_1 クエリ

text_1 が分析されると、elasticsearch が行うことの 1 つは、フィールドを小文字に変換することです。したがって、次のクエリを実行すると、ドキュメントが見つかりません。

curl -XGET 'http://localhost:9200/test/test/_search?pretty=true' -d '
{ "query": { "prefix" : { "text_1": "H"} } }
'
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

しかし、トリックを実行して小文字を使用してクエリを作成すると、次のようになります。

curl -XGET 'http://localhost:9200/test/test/_search?pretty=true' -d '
{ "query": { "prefix" : { "text_1": "h"} } }
'
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "test",
      "_type" : "test",
      "_id" : "1",
      "_score" : 1.0, "_source" :
{
"text_1" : "Hello world",
"text_2" : "Hello world"
}
    } ]
  }
}

text_2 クエリ

text_2 は分析されていないため、元のクエリを作成すると一致します。

curl -XGET 'http://localhost:9200/test/test/_search?pretty=true' -d '
{ "query": { "prefix" : { "text_2": "H"} } }
'
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "test",
      "_type" : "test",
      "_id" : "1",
      "_score" : 1.0, "_source" :
{
"text_1" : "Hello world",
"text_2" : "Hello world"
}
    } ]
  }
}
于 2013-08-26T16:10:38.500 に答える