Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid JSON Being Returned #18076

Closed
shawn-digitalpoint opened this issue Apr 30, 2016 · 7 comments · Fixed by #18939
Closed

Invalid JSON Being Returned #18076

shawn-digitalpoint opened this issue Apr 30, 2016 · 7 comments · Fixed by #18939
Assignees
Labels
>bug :Core/Infra/REST API REST infrastructure and utilities

Comments

@shawn-digitalpoint
Copy link

Elasticsearch version:
2.3.2

JVM version:
1.8.0_60 OpenJDK 64-Bit Server VM 25.60-b23 Oracle Corporation

OS version:
OpenSUSE Leap 42.1

Description of the problem including expected versus actual behavior:
Invalid JSON returned in Elasticsearch results. Expect results from Elasticsearch to be valid JSON.

Steps to reproduce:
We have an aggregation that includes longitude, latitude and location name separated by a pipe. ES isn't escaping the quotes within one of them. ES returns this as results:

{"took":59,"aggregations":{"time_group":{"buckets":[{"key":78469,"d":{"buckets":[{"d":{"buckets":[{"key":"34.774663|-112.467699|Chino Valley Fire Department"}]}}]},"w":{"value":1.0}},{"key":78388,"d":{"buckets":[{"d":{"buckets":[{"key":"34.775424|-112.452459|Windmill 7"}]}}]},"w":{"value":1.0}},{"key":78333,"d":{"buckets":[{"d":{"buckets":[{"key":"34.773574|-112.465953|"19 Remembered" Hotshot Honors"}]}}]},"w":{"value":1.0}},{"key":78309,"d":{"buckets":[{"d":{"buckets":[{"key":"34.773311|-112.46529|Chino Valley Saluted America's Heros"}]}}]},"w":{"value":1.0}},{"key":78305,"d":{"buckets":[{"d":{"buckets":[{"key":"34.77383|-112.465432|Chino Valley Public Library"}]}}]},"w":{"value":1.0}},{"key":78112,"d":{"buckets":[{"d":{"buckets":[{"key":"34.769398|-112.447186|Chino Valley Community Center Park"}]}}]},"w":{"value":1.0}},{"key":77976,"d":{"buckets":[{"d":{"buckets":[{"key":"34.777816|-112.447498|Stoned Security Donkey"}]}}]},"w":{"value":1.0}},{"key":77830,"d":{"buckets":[{"d":{"buckets":[{"key":"34.772045|-112.427787|Peavine Trails"}]}}]},"w":{"value":1.0}},{"key":77585,"d":{"buckets":[{"d":{"buckets":[{"key":"34.644372|-112.432358|Prescott Municipal Airport"}]}}]},"w":{"value":1.0}},{"key":77371,"d":{"buckets":[{"d":{"buckets":[{"key":"34.760367|-112.447588|Hope Lutheran Church"}]}}]},"w":{"value":1.0}},{"key":56892,"d":{"buckets":[{"d":{"buckets":[{"key":"35.483665|-111.556402|Coconino National Forest"}]}}]},"w":{"value":0.89}},{"key":51987,"d":{"buckets":[{"d":{"buckets":[{"key":"35.313604|-112.852838|Seligman, Arizona"}]}}]},"w":{"value":0.84}}]}}}

Specifically this bucket key isn't escaped:

{"key":"34.773574|-112.465953|"19 Remembered" Hotshot Honors"}

@shawn-digitalpoint
Copy link
Author

Found a workaround... if you don't use the filter_path, the results are properly escaped.

@jpountz
Copy link
Contributor

jpountz commented May 1, 2016

@shawn-digitalpoint then this looks like a bug in how filter_path works. Can you share your request (including the filter_path)?

@shawn-digitalpoint
Copy link
Author

shawn-digitalpoint commented May 2, 2016

Using PHP to build the JSON, but this is the PHP array (not sure why github's code block isn't working, sorry...):

$params = array(
  'size' => 0,
  'sort' => array(
    'date' => array(
      'order' => 'desc'
    )
  ),
  'query' => array(
    'bool' => array(
      'must' => array(
        array(
          'match' => array(
            'attacking_agent_id' => 100,
          ),
        ),
        array(
          'range' => array(
            'date' => array(
              'gte' => 1430606758
            )
          ),
        ),
      )
    )
  ),
  'aggs' => array(
    'time_group' => array(
      'terms' => array(
        'field' => 'location_id',
        'size' => 100000,
        'order'=> array(
          '_term' => 'desc'
        ),
      ),

      'aggs' => array(
        'd' => array(
          'terms' => array(
            'field' => 'timegroup_agent',
            'size' => 1
          ),
          'aggs' => array(
            'd' => array(
              'terms' => array(
                'field' => 'raw_geo_name',
                'size' => 1
              )
            ),
          )
        ),
        'total_date' => array(
          'sum' => array(
            'field' => 'date'
          )
        ),
        'unique_attacks' => array(
          'cardinality' => array(
            "field" => "timegroup_agent"
          )
        ),

        "w" => array (
          'bucket_script' => array(
            'buckets_path' => array(
              'totalDate' => 'total_date',
              'unique' => 'unique_attacks',
              'docCount' => '_count',
            ),
            "script" => 'min(' . $maxWeight . ', max(' . $minWeight . ', round(((' . ($daysBack * 86400) . ' * docCount) - ((' . (XenForo_Application::$time) . ' * docCount) - totalDate)) / docCount / ' . ($daysBack * 86400) . ' * unique * 100) / 100))'  // round(((' . ($daysBack * 86400)  . ' * docCount) - ((' . XenForo_Application::$time . ' * docCount) - totalDate)) / ' . ($daysBack * 86400) . ' * 100) / 100
          )
        ),
      )
    ),
  )
);

@shawn-digitalpoint
Copy link
Author

Oh, and the filter_path used when getting invalid JSON is:

took,aggregations.time_group.buckets.key,aggregations.time_group.buckets.d.buckets.d.buckets.key,aggregations.time_group.buckets.w

@jpountz jpountz added help wanted adoptme and removed feedback_needed labels May 4, 2016
@tlrx tlrx removed the help wanted adoptme label May 6, 2016
@tlrx
Copy link
Member

tlrx commented May 6, 2016

Thanks for reporting! It's probably a Jackson bug so I created FasterXML/jackson-core/pull/280 to see and discuss this issue with the Jackson team. I'll update this issue once I have some feedback.

@tlrx
Copy link
Member

tlrx commented May 9, 2016

The Jackson issue has been confirmed and merged. This issue will be resolved once we move on a new release of jackson-core that integrates the fix.

@s1monw
Copy link
Contributor

s1monw commented May 9, 2016

awesome @tlrx great to fix this kind of stuff upstream directly!

tlrx added a commit to tlrx/elasticsearch that referenced this issue Aug 5, 2016
This commit updates Jackson to the 2.8.1 version, which is more strict when it comes to build objects. It also adds the snakeyaml dependency that was previously shaded in jackson libs.

It also closes elastic#18076
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/REST API REST infrastructure and utilities
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants