From b7e4de969fbff47e6bea6d94892f6f3bffc30a5f Mon Sep 17 00:00:00 2001 From: adityaagrawal Date: Thu, 3 May 2018 21:10:16 +0530 Subject: [PATCH 1/4] assign field term vector with empty terms when null. --- .../elasticsearch/action/termvectors/TermVectorsWriter.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java index 06eea6367edca..8a54406c1f9cb 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java @@ -70,6 +70,10 @@ void setFields(Fields termVectorsByField, Set selectedFields, EnumSet Date: Fri, 4 May 2018 18:12:43 +0530 Subject: [PATCH 2/4] Add test for more like this in case of zero tokens in one of the field. --- .../search/morelikethis/MoreLikeThisIT.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java b/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java index 3487de255e164..e8097f61c1ea4 100644 --- a/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java +++ b/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java @@ -91,6 +91,38 @@ public void testSimpleMoreLikeThis() throws Exception { assertHitCount(response, 1L); } + //Issue #30148 + public void testMoreLikeThisForZeroTokensInOneOfTheAnalyzedFields() throws Exception { + CreateIndexRequestBuilder createIndexRequestBuilder = prepareCreate("test") + .addMapping("type", jsonBuilder() + .startObject().startObject("type") + .startObject("properties") + .startObject("myField").field("type", "text").endObject() + .startObject("empty").field("type", "text").endObject() + .endObject() + .endObject().endObject()); + + assertAcked(createIndexRequestBuilder); + + ensureGreen(); + + client().index(indexRequest("test").type("type").id("1").source(jsonBuilder().startObject() + .field("myField", "and_foo").field("empty", "").endObject())).actionGet(); + + + client().index(indexRequest("test").type("type").id("2").source(jsonBuilder().startObject() + .field("myField", "and_foo").field("empty", "").endObject())).actionGet(); + + client().admin().indices().refresh(refreshRequest()).actionGet(); + + SearchResponse searchResponse = client().prepareSearch().setQuery( + moreLikeThisQuery(new String[]{"myField", "empty"}, null, new Item[]{new Item("test", "type", "1")}) + .minTermFreq(1).minDocFreq(1) + ).get(); + + assertHitCount(searchResponse, 1L); + } + public void testSimpleMoreLikeOnLongField() throws Exception { logger.info("Creating index test"); assertAcked(prepareCreate("test") From 8bf0c24a916bb4511ae886e937a25e2eeeb0a5fe Mon Sep 17 00:00:00 2001 From: adityaagrawal Date: Tue, 8 May 2018 01:00:08 +0530 Subject: [PATCH 3/4] Update changelog and remove empty lines. --- docs/CHANGELOG.asciidoc | 4 ++++ .../org/elasticsearch/search/morelikethis/MoreLikeThisIT.java | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.asciidoc b/docs/CHANGELOG.asciidoc index dc2092ad9050a..e4c8253a413df 100644 --- a/docs/CHANGELOG.asciidoc +++ b/docs/CHANGELOG.asciidoc @@ -29,6 +29,8 @@ Fail snapshot operations early when creating or deleting a snapshot on a repository that has been written to by an older Elasticsearch after writing to it with a newer Elasticsearch version. ({pull}30140[#30140]) +Fix NPE in 'more_like_this' when field has zero tokens ({pull}30365[#30365]) + === Regressions === Known Issues @@ -41,6 +43,8 @@ written to by an older Elasticsearch after writing to it with a newer Elasticsea === Bug Fixes +Fix NPE in 'more_like_this' when field has zero tokens ({pull}30365[#30365]) + === Regressions === Known Issues diff --git a/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java b/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java index e8097f61c1ea4..21c043aa65616 100644 --- a/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java +++ b/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java @@ -108,8 +108,6 @@ public void testMoreLikeThisForZeroTokensInOneOfTheAnalyzedFields() throws Excep client().index(indexRequest("test").type("type").id("1").source(jsonBuilder().startObject() .field("myField", "and_foo").field("empty", "").endObject())).actionGet(); - - client().index(indexRequest("test").type("type").id("2").source(jsonBuilder().startObject() .field("myField", "and_foo").field("empty", "").endObject())).actionGet(); From d507d372efe6ce10be55410c4a560cf7007940eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Tue, 8 May 2018 11:42:31 +0200 Subject: [PATCH 4/4] Update CHANGELOG.asciidoc --- docs/CHANGELOG.asciidoc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.asciidoc b/docs/CHANGELOG.asciidoc index bad57f22fd496..346290c9f76f9 100644 --- a/docs/CHANGELOG.asciidoc +++ b/docs/CHANGELOG.asciidoc @@ -104,11 +104,11 @@ ones that the user is authorized to access in case field level security is enabl [float] === Bug Fixes +Fix NPE in 'more_like_this' when field has zero tokens ({pull}30365[#30365]) + Fixed prerelease version of elasticsearch in the `deb` package to sort before GA versions ({pull}29000[#29000]) -Fix NPE in 'more_like_this' when field has zero tokens ({pull}30365[#30365]) - Rollup:: * Validate timezone in range queries to ensure they match the selected job when searching ({pull}30338[#30338]) @@ -118,7 +118,6 @@ searching ({pull}30338[#30338]) Fail snapshot operations early when creating or deleting a snapshot on a repository that has been written to by an older Elasticsearch after writing to it with a newer Elasticsearch version. ({pull}30140[#30140]) -=== Regressions Fix NPE when CumulativeSum agg encounters null value/empty bucket ({pull}29641[#29641]) Do not fail snapshot when deleting a missing snapshotted file ({pull}30332[#30332]) @@ -174,7 +173,6 @@ Added put index template API to the high level rest client ({pull}30400[#30400]) Fix NPE in 'more_like_this' when field has zero tokens ({pull}30365[#30365]) -=== Regressions Do not ignore request analysis/similarity settings on index resize operations when the source index already contains such settings ({pull}30216[#30216]) Fix NPE when CumulativeSum agg encounters null value/empty bucket ({pull}29641[#29641])