1

私はjdbc リバーを使用しており、次のインデックスを作成できます。

curl -XPUT 'localhost:9201/_river/email/_meta' -d '{
    "type" : "jdbc",
    "jdbc" : {
        "strategy":"simple", 
        "poll":"10",
        "driver" : "org.postgresql.Driver",
        "url" : "jdbc:postgresql://localhost:5432/api_development",
        "username" : "paulcowan",
        "password" : "",
        "sql" : "SELECT id, subject, body, personal, sent_at, read_by, account_id, sender_user_id, sender_contact_id, html, folder, draft FROM emails"
    },
    "index" : {
        "index" : "email",
        "type" : "jdbc"
    },
    "mappings" : {
        "email" : {
      "properties" : {
        "account_id" : { "type" : "integer" },
        "subject" : { "type" : "string" },
        "body" : { "type" : "string" },
        "html" : { "type" : "string" },
        "folder" : { "type" : "string", "index" : "not_analyzed" },
        "id" : { "type" : "integer" }
      }
      }
    }
}'

次のように curl を使用して基本的なクエリを実行できます。

curl -XGET 'http://localhost:9201/email/jdbc/_search?pretty&q=fullcontact'

結果が返ってきます

しかし、私がやりたいのは、結果を特定の電子メールaccount_idと特定の電子メールに制限することです。次のクエリを実行します。

curl -XGET 'http://localhost:9201/email/jdbc/_search' -d '{
  "query": {
    "filtered": {
      "filter": {
        "and": [
          {
            "term": {
              "folder": "INBOX"
            }
          },
          {
            "term": {
              "account_id": 1
            }
          }
        ]
      },
      "query": {
        "query_string": {
          "query": "fullcontact*"
        }
      }
    }
  }
}'

次の結果が得られます。

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

クエリの何が問題なのか誰か教えてもらえますか?

4

1 に答える 1

0

type_mapping セクションを使用して、通常のマッピングノードが無視される jdbc リバーでフィールドが not_analyzed であることを指定する必要があることがわかりました。

以下はそれがどのようになったかです:

curl -XPUT 'localhost:9200/_river/your_index/_meta' -d '{
    "type" : "jdbc",
    "jdbc" : {
        "strategy":"simple", 
        "poll":"10",
        "driver" : "org.postgresql.Driver",
        "url" : "jdbc:postgresql://localhost:5432/api_development",
        "username" : "user",
        "password" : "your_password",
        "sql" : "SELECT field_one, field_two, field_three, the_rest FROM blah"
    },
    "index" : {
        "index" : "your_index",
        "type" : "jdbc",
    "type_mapping": "{\"your_index\" : {\"properties\" : {\"field_two\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}}"
    }
}'

奇妙なことに、または厄介なことに、type_mapping セクションは、通常の json ノードではなく、json でエンコードされた文字列を取ります。

次を実行してマッピングを確認できます。

# check mappings
curl -XGET 'http://localhost:9200/your_index/jdbc/_mapping?pretty=true'

次のようなものが得られるはずです:

{
  "jdbc" : {
    "properties" : {
      "field_one" : {
        "type" : "long"
      },
      "field_two" : {
        "type" : "string",
        "index" : "not_analyzed",
        "omit_norms" : true,
        "index_options" : "docs"
      },
      "field_three" : {
        "type" : "string"
      }
    }
  }
}
于 2013-12-10T11:47:11.023 に答える