[ 
https://issues.apache.org/jira/browse/CAMEL-12034?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Radoslav Cincala updated CAMEL-12034:
-------------------------------------
    Description: 
Hi,

I am using camel-elasticsearch5 component of Camel 2.20.1.
I have found and issue. The description follows.

*If you use Map or String in message body for SEARCH operation, "size" and 
"from" parameters are always ignored hence you always get just default 10 
results.*

For example - if your map contains query like this: 
(in terms of simplicity - following is String representation of the map):
{code}
{size=50, query={query_string={query=status:ACTIVE}}, from=0}
{code}

Issue I suspect is present in class: 
_org.apache.camel.component.elasticsearch5.converter.ElasticsearchActionRequestConverter_
and its method 
_public static SearchRequest toSearchRequest(Object queryObject, Exchange 
exchange)_
{code}
// line 191...
if (queryObject instanceof Map<?, ?>) {
            Map<String, Object> mapQuery = (Map<String, Object>)queryObject;
            // Remove 'query' prefix from the query object for backward 
compatibility
            if 
(mapQuery.containsKey(ElasticsearchConstants.ES_QUERY_DSL_PREFIX)) {
                mapQuery = (Map<String, 
Object>)mapQuery.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
            }
            try {
                XContentBuilder contentBuilder = 
XContentFactory.contentBuilder(XContentType.JSON);
                queryText = contentBuilder.map(mapQuery).string();
            } catch (IOException e) {
                LOG.error(e.getMessage());
            }
        }

// queryText then used on line 220...
searchSourceBuilder.query(QueryBuilders.wrapperQuery(queryText));
searchRequest.source(searchSourceBuilder);

return searchRequest;
{code}
Inner if condition basically extracts only query part from the map 
{code}
query={query_string={query=status:ACTIVE}
{code}
and *"size" and "from" get lost from the query*
{code}
// line 194...
if (mapQuery.containsKey(ElasticsearchConstants.ES_QUERY_DSL_PREFIX)) {
                mapQuery = (Map<String, 
Object>)mapQuery.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
// ...where ElasticsearchConstants.ES_QUERY_DSL_PREFIX = "query"
}
{code}
Same issue is with usage of the String in the message body:
{code}
// line 203
} else if (queryObject instanceof String) {
            queryText = (String)queryObject;
            ObjectMapper mapper = new ObjectMapper();
            try {
                JsonNode jsonTextObject = mapper.readValue(queryText, 
JsonNode.class);
                JsonNode parentJsonNode = 
jsonTextObject.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
                if (parentJsonNode != null) {
                    queryText = parentJsonNode.toString();
                }
            } catch (IOException e) {
                LOG.error(e.getMessage());
            }
        }
{code}

Only workaround for this is to use *SearchRequest* object in a message body 
where you can explicitly set "size" and "from" on SearchSourceBuilder object. 
For example:
{code}
SearchRequest searchRequest = new SearchRequest("my_index")
            .types("my_type")
            .source(new 
SearchSourceBuilder().query(QueryBuilders.wrapperQuery("my:query"))
                .size(50).from(0));
{code}
I don't know what was the developer's intention for having such a condition 
which removes these parameters from the query.

Thank you very much in advance if anybody can have a look and verify if this is 
a valid concern.

  was:
Hi,

I am using camel-elasticsearch5 component of Camel 2.20.1.
I have found and issue. The description follows.

*If you use Map or String in message body for SEARCH operation, "size" and 
"from" parameters are always ignored hence you always get just default 10 
results.*

For example - if your map contains query like this: 
(in terms of simplicity - following is String representation of the map):
{code}
{size=50, query={query_string={query=status:ACTIVE}}, from=0}
{code}

Issue I suspect is present in class: 
_org.apache.camel.component.elasticsearch5.converter.ElasticsearchActionRequestConverter_
and its method 
_public static SearchRequest toSearchRequest(Object queryObject, Exchange 
exchange)_
{code}
// line 191...
if (queryObject instanceof Map<?, ?>) {
            Map<String, Object> mapQuery = (Map<String, Object>)queryObject;
            // Remove 'query' prefix from the query object for backward 
compatibility
            if 
(mapQuery.containsKey(ElasticsearchConstants.ES_QUERY_DSL_PREFIX)) {
                mapQuery = (Map<String, 
Object>)mapQuery.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
            }
            try {
                XContentBuilder contentBuilder = 
XContentFactory.contentBuilder(XContentType.JSON);
                queryText = contentBuilder.map(mapQuery).string();
            } catch (IOException e) {
                LOG.error(e.getMessage());
            }
        }
{code}
Inner if condition basically extracts only query part from the map 
{code}
query={query_string={query=status:ACTIVE}
{code}
and *"size" and "from" get lost from the query*
{code}
// line 194...
if (mapQuery.containsKey(ElasticsearchConstants.ES_QUERY_DSL_PREFIX)) {
                mapQuery = (Map<String, 
Object>)mapQuery.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
// ...where ElasticsearchConstants.ES_QUERY_DSL_PREFIX = "query"
}
{code}
Same issue is with usage of the String in the message body:
{code}
// line 203
} else if (queryObject instanceof String) {
            queryText = (String)queryObject;
            ObjectMapper mapper = new ObjectMapper();
            try {
                JsonNode jsonTextObject = mapper.readValue(queryText, 
JsonNode.class);
                JsonNode parentJsonNode = 
jsonTextObject.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
                if (parentJsonNode != null) {
                    queryText = parentJsonNode.toString();
                }
            } catch (IOException e) {
                LOG.error(e.getMessage());
            }
        }
{code}

Only workaround for this is to use *SearchRequest* object in a message body 
where you can explicitly set "size" and "from" on SearchSourceBuilder object. 
For example:
{code}
SearchRequest searchRequest = new SearchRequest("my_index")
            .types("my_type")
            .source(new 
SearchSourceBuilder().query(QueryBuilders.wrapperQuery("my:query"))
                .size(50).from(0));
{code}
I don't know what was the developer's intention for having such a condition 
which removes these parameters from the query.

Thank you very much in advance if anybody can have a look and verify if this is 
a valid concern.


> Search Operation: If Map or String is used in Message Body, "size" and "from" 
> parameters are always ignored (lost while conversion).
> ------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-12034
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12034
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-elasticsearch5
>    Affects Versions: 2.20.1
>            Reporter: Radoslav Cincala
>            Priority: Minor
>
> Hi,
> I am using camel-elasticsearch5 component of Camel 2.20.1.
> I have found and issue. The description follows.
> *If you use Map or String in message body for SEARCH operation, "size" and 
> "from" parameters are always ignored hence you always get just default 10 
> results.*
> For example - if your map contains query like this: 
> (in terms of simplicity - following is String representation of the map):
> {code}
> {size=50, query={query_string={query=status:ACTIVE}}, from=0}
> {code}
> Issue I suspect is present in class: 
> _org.apache.camel.component.elasticsearch5.converter.ElasticsearchActionRequestConverter_
> and its method 
> _public static SearchRequest toSearchRequest(Object queryObject, Exchange 
> exchange)_
> {code}
> // line 191...
> if (queryObject instanceof Map<?, ?>) {
>             Map<String, Object> mapQuery = (Map<String, Object>)queryObject;
>             // Remove 'query' prefix from the query object for backward 
> compatibility
>             if 
> (mapQuery.containsKey(ElasticsearchConstants.ES_QUERY_DSL_PREFIX)) {
>                 mapQuery = (Map<String, 
> Object>)mapQuery.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
>             }
>             try {
>                 XContentBuilder contentBuilder = 
> XContentFactory.contentBuilder(XContentType.JSON);
>                 queryText = contentBuilder.map(mapQuery).string();
>             } catch (IOException e) {
>                 LOG.error(e.getMessage());
>             }
>         }
> // queryText then used on line 220...
> searchSourceBuilder.query(QueryBuilders.wrapperQuery(queryText));
> searchRequest.source(searchSourceBuilder);
> return searchRequest;
> {code}
> Inner if condition basically extracts only query part from the map 
> {code}
> query={query_string={query=status:ACTIVE}
> {code}
> and *"size" and "from" get lost from the query*
> {code}
> // line 194...
> if (mapQuery.containsKey(ElasticsearchConstants.ES_QUERY_DSL_PREFIX)) {
>                 mapQuery = (Map<String, 
> Object>)mapQuery.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
> // ...where ElasticsearchConstants.ES_QUERY_DSL_PREFIX = "query"
> }
> {code}
> Same issue is with usage of the String in the message body:
> {code}
> // line 203
> } else if (queryObject instanceof String) {
>             queryText = (String)queryObject;
>             ObjectMapper mapper = new ObjectMapper();
>             try {
>                 JsonNode jsonTextObject = mapper.readValue(queryText, 
> JsonNode.class);
>                 JsonNode parentJsonNode = 
> jsonTextObject.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
>                 if (parentJsonNode != null) {
>                     queryText = parentJsonNode.toString();
>                 }
>             } catch (IOException e) {
>                 LOG.error(e.getMessage());
>             }
>         }
> {code}
> Only workaround for this is to use *SearchRequest* object in a message body 
> where you can explicitly set "size" and "from" on SearchSourceBuilder object. 
> For example:
> {code}
> SearchRequest searchRequest = new SearchRequest("my_index")
>             .types("my_type")
>             .source(new 
> SearchSourceBuilder().query(QueryBuilders.wrapperQuery("my:query"))
>                 .size(50).from(0));
> {code}
> I don't know what was the developer's intention for having such a condition 
> which removes these parameters from the query.
> Thank you very much in advance if anybody can have a look and verify if this 
> is a valid concern.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to