弹簧数据弹性搜索未在字段上正确搜索

时间:2020-05-03 18:58:50

标签: spring elasticsearch spring-data-elasticsearch

我想搜索索引的三个字段:标题,authorName和Description;

我的搜索如下:

SearchQuery searchQuery = new NativeSearchQueryBuilder()
                                .withQuery(QueryBuilders.multiMatchQuery(criteria)
                                .field("title")
                                .field("authorName")
                                .field("description")
                                .type(MultiMatchQueryBuilder.Type.BEST_FIELDS))
                                .withPageable(PageRequest.of(page, size))
                                .build();
            Page<Ebook> ebookList = ebookRepo.search(searchQuery);

我已将这些文档编入索引:

{
  "took" : 12,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 5,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "ebook",
        "_type" : "ebook",
        "_id" : "9",
        "_score" : 1.0,
        "_source" : {
          "id" : 9,
          "size" : null,
          "numberOfPages" : 10,
          "companyId" : 656,
          "price" : 10.0,
          "title" : "Welcome to my life",
          "authorName" : "JB2",
          "description" : "Welcome to my life 3",
          "language" : "FR",
          "ebookPath" : null,
          "ebookDownloadUrl" : null,
          "rating" : {
            "ratingId" : 10,
            "average" : 5.0,
            "starsByUserId" : {
              "131" : 5
            },
            "stars" : {
              "5" : 1
            }
          },
          "coverPath" : null,
          "coverDownloadUrl" : null,
          "iconPath" : null,
          "iconDownloadUrl" : null,
          "category" : {
            "id" : 1,
            "name" : "Webtoon",
            "subCategoryList" : [ ]
          },
          "subCategory" : {
            "id" : 2,
            "name" : "Adventure"
          },
          "repositoryGeneratedId" : "1588336718863",
          "userReview" : [
            {
              "id" : 11,
              "comment" : "I dont like it. I give 5 stars",
              "commentDate" : 1588336718989,
              "appUserId" : 131,
              "stars" : 5
            }
          ],
          "status" : "INITIATED"
        }
      },
      {
        "_index" : "ebook",
        "_type" : "ebook",
        "_id" : "5",
        "_score" : 1.0,
        "_source" : {
          "id" : 5,
          "size" : null,
          "numberOfPages" : 10,
          "companyId" : 2,
          "price" : 10,
          "title" : "Welcome to my life",
          "authorName" : "kosted 3",
          "description" : "Ceci est une autre description 3",
          "language" : "FR",
          "ebookPath" : null,
          "ebookDownloadUrl" : null,
          "rating" : {
            "ratingId" : 6,
            "average" : 0.0,
            "starsByUserId" : { },
            "stars" : { }
          },
          "coverPath" : null,
          "coverDownloadUrl" : null,
          "iconPath" : null,
          "iconDownloadUrl" : null,
          "category" : {
            "id" : 1,
            "name" : "Webtoon"
          },
          "subCategory" : {
            "id" : 2,
            "name" : "Adventure"
          },
          "repositoryGeneratedId" : "1588372761403",
          "userReview" : [ ],
          "status" : "INITIATED"
        }
      },
      {
        "_index" : "ebook",
        "_type" : "ebook",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "id" : 3,
          "size" : null,
          "numberOfPages" : 10,
          "companyId" : 2,
          "price" : 10,
          "title" : "Welcome to my life",
          "authorName" : "kosted 2",
          "description" : "Ceci est une autre description 2",
          "language" : "FR",
          "ebookPath" : null,
          "ebookDownloadUrl" : null,
          "rating" : {
            "ratingId" : 4,
            "average" : 0.0,
            "starsByUserId" : { },
            "stars" : { }
          },
          "coverPath" : null,
          "coverDownloadUrl" : null,
          "iconPath" : null,
          "iconDownloadUrl" : null,
          "category" : {
            "id" : 1,
            "name" : "Webtoon"
          },
          "subCategory" : {
            "id" : 2,
            "name" : "Adventure"
          },
          "repositoryGeneratedId" : "1588372758036",
          "userReview" : [ ],
          "status" : "INITIATED"
        }
      },
      {
        "_index" : "ebook",
        "_type" : "ebook",
        "_id" : "6",
        "_score" : 1.0,
        "_source" : {
          "id" : 6,
          "size" : null,
          "numberOfPages" : 10,
          "companyId" : 655,
          "price" : 10,
          "title" : "Welcome to my life",
          "authorName" : "JBB",
          "description" : "Welcome to my life 2",
          "language" : "FR",
          "ebookPath" : null,
          "ebookDownloadUrl" : null,
          "rating" : {
            "ratingId" : 7,
            "average" : 0.0,
            "starsByUserId" : { },
            "stars" : { }
          },
          "coverPath" : null,
          "coverDownloadUrl" : null,
          "iconPath" : null,
          "iconDownloadUrl" : null,
          "category" : {
            "id" : 1,
            "name" : "Webtoon",
            "subCategoryList" : [ ]
          },
          "subCategory" : {
            "id" : 2,
            "name" : "Adventure"
          },
          "repositoryGeneratedId" : "1588336718576",
          "userReview" : [ ],
          "status" : "INITIATED"
        }
      },
      {
        "_index" : "ebook",
        "_type" : "ebook",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "id" : 1,
          "size" : null,
          "numberOfPages" : 10,
          "companyId" : 2,
          "price" : 10,
          "title" : "Welcome to my life",
          "authorName" : "kosted",
          "description" : "Book about my life",
          "language" : "FR",
          "ebookPath" : null,
          "ebookDownloadUrl" : null,
          "rating" : {
            "ratingId" : 2,
            "average" : 0.0,
            "starsByUserId" : { },
            "stars" : { }
          },
          "coverPath" : null,
          "coverDownloadUrl" : null,
          "iconPath" : null,
          "iconDownloadUrl" : null,
          "category" : {
            "id" : 1,
            "name" : "Webtoon"
          },
          "subCategory" : {
            "id" : 2,
            "name" : "Adventure"
          },
          "repositoryGeneratedId" : "1588372748126",
          "userReview" : [ ],
          "status" : "INITIATED"
        }
      }
    ]
  }
}

当我使用术语“ JB”或“ jb”甚至“ JB2”进行搜索时,当存在authorName为JB2的电子书时,我得到0个结果。

我使用spring 2.2.4.RELEASE和spring数据弹性搜索3.2.4.RELEASE。 我在代码中做错了什么?关于如何纠正它的任何想法吗? 预先感谢

0 个答案:

没有答案
相关问题