0

インデックスに対してクエリを実行し、グラバター画像を持つレビュアーがいないすべてのレビューを取得しようとしています。これを行うために、ホスト パターンを使用して PatternAnalyzerDefinition を実装しました。

"^https?\\:\\/\\/([^\\/?#]+)(?:[\\/?#]|$)"

次のような URL のホストに一致して抽出する必要があります。

https://www.gravatar.com/avatar/blablalbla?s=200&r=pg&d=mm

になります:

www.gravatar.com

マッピング:

clientProvider.getClient.execute {
          create.index(_index).analysis(
            phraseAnalyzer,
            PatternAnalyzerDefinition("host_pattern", regex = "^https?\\:\\/\\/([^\\/?#]+)(?:[\\/?#]|$)")
          ).mappings(
"reviews" as (
             .... Cool mmappings
              "review" inner (
                "grade" typed LongType,
                "text" typed StringType index "not_analyzed",
                "reviewer" inner (
                  "screenName" typed StringType index "not_analyzed",
                  "profilePicture" typed StringType analyzer "host_pattern",
                  "thumbPicture" typed StringType index "not_analyzed",
                  "points" typed LongType index "not_analyzed"
                ),                    
               .... Other cool mmappings                    
              )
            ) all(false)
} map { response =>
      Logger.info("Create index response: {}", response)
    } recover {
      case t: Throwable => play.Logger.error("Error creating index: ", t)
    }

クエリ:

val reviewQuery = (search in path)
      .query(
        bool(
          must(
            not(
              termQuery("review.reviewer.profilePicture", "www.gravatar.com")
            )
          )
        )
      )
      .postFilter(
        bool(
          must(
            rangeFilter("review.grade") from 3
          )
        )
      )
      .size(size)
      .sort(by field "review.created" order SortOrder.DESC)

    clientProvider.getClient.execute {      
      reviewQuery
    }.map(_.getHits.jsonToList[ReviewData])

マッピングのインデックスを確認します。

reviewer: {
    properties: {
        id: {
            type: "long"
        },
        points: {
            type: "long"
        },
        profilePicture: {
            type: "string",
            analyzer: "host_pattern"
        },
        screenName: {
            type: "string",
            index: "not_analyzed"
        },
        state: {
            type: "string"
        },
        thumbPicture: {
            type: "string",
            index: "not_analyzed"
        }
    }
}

クエリを実行すると、パターン マッチングが機能しないようです。グラバター画像を持っているレビュアーから、今でもレビューをもらいます。私は何を間違っていますか?多分私は PatternAnalyzer を誤解しましたか?

私は "com.sksamuel.elastic4s" %% "elastic4s" % "1.5.9" を使用しています。

4

1 に答える 1