Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

JSON in alias filter is unnecessarily escaped #127

Closed
igor-kupczynski opened this issue Jun 16, 2014 · 5 comments
Closed

JSON in alias filter is unnecessarily escaped #127

igor-kupczynski opened this issue Jun 16, 2014 · 5 comments
Labels

Comments

@igor-kupczynski
Copy link
Contributor

Hi,

If you want to create an alias with a filter you should use a json like this ([src])(http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html):

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
    "actions" : [
        {
            "add" : {
                 "index" : "test1",
                 "alias" : "alias2",
                 "filter" : { "term" : { "user" : "kimchy" } }
            }
        }
    ]
}'

The problem is that JEST escapes the JSON query in the filter object which results in something like this:

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
    "actions" : [
        {
            "add" : {
                 "index" : "test1",
                 "alias" : "alias2",
                 "filter" : { \"term\" : { \"user\" : \"kimchy\" } }
            }
        }
    ]
}'

I'll submit a test case shortly...

@igor-kupczynski
Copy link
Contributor Author

For example this test

Index: jest-common/src/test/java/io/searchbox/indices/aliases/AddAliasMappingTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- jest-common/src/test/java/io/searchbox/indices/aliases/AddAliasMappingTest.java (revision 59b4e9f6b8b21ed5a9edcf4366ed5473174cc347)
+++ jest-common/src/test/java/io/searchbox/indices/aliases/AddAliasMappingTest.java (revision )
@@ -37,11 +37,12 @@
     public void testGetDataForJsonWithFilterAndRouting() {
         AddAliasMapping addAliasMapping = new AddAliasMapping
                 .Builder("tIndex", "tAlias")
-                .setFilter("my_query")
+                .setFilter("{\"term\":{\"user\":\"kimchy\"}}")
                 .addRouting("1")
                 .build();
         String actualJson = new Gson().toJson(addAliasMapping.getData()).toString();
-        String expectedJson = "[{\"add\":{\"search_routing\":\"1\",\"index\":\"tIndex\",\"alias\":\"tAlias\",\"index_routing\":\"1\",\"filter\":\"my_query\"}}]";
+        String expectedJson = "[{\"add\":{\"search_routing\":\"1\",\"index\":\"tIndex\",\"alias\":\"tAlias\"," +
+                "\"index_routing\":\"1\",\"filter\":\"{\"term\":{\"user\":\"kimchy\"}}\"}}]";

         assertEquals(expectedJson, actualJson);
     }

Fails with a message:

org.junit.ComparisonFailure: 
Expected :[{"add":{"search_routing":"1","index":"tIndex","alias":"tAlias","index_routing":"1","filter":"{"term":{"user":"kimchy"}}"}}]
Actual   :[{"add":{"search_routing":"1","index":"tIndex","alias":"tAlias","index_routing":"1","filter":"{\"term\":{\"user\":\"kimchy\"}}"}}]

Should this #setFilter(String) be changed to #setFilter(JsonObject)? What do you think?

@igor-kupczynski
Copy link
Contributor Author

Hi, I posted a possible solution, can you take a look and advise what needs to be done to get it merged to JEST?

@kramer kramer added the bug label Jun 16, 2014
@kramer
Copy link
Member

kramer commented Jun 16, 2014

Thanks for the clean bug report and the contribution, we really appreciate it. Please see my comments on #128 for further discussion.

kramer pushed a commit that referenced this issue Jun 17, 2014
Issue #127, JSON in alias filter is unnecessarily escaped. Changed Strin...
@kramer
Copy link
Member

kramer commented Jun 17, 2014

Merged #128, thanks again for the contribution.

@kramer kramer closed this as completed Jun 17, 2014
@igor-kupczynski
Copy link
Contributor Author

NP, Thanks for merging

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants