Skip to content

Instantly share code, notes, and snippets.

@hkorte
Last active August 29, 2015 13:58
Show Gist options
  • Save hkorte/9974567 to your computer and use it in GitHub Desktop.
Save hkorte/9974567 to your computer and use it in GitHub Desktop.
This gist describes different problems in Elasticsearch 1.1.0 and in the current master (2014-04-04) with the field resolution in the significant terms aggregations when prepending the document type to the field name.
curl -XDELETE 'http://localhost:9200/testindex?pretty=true'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc01?pretty=true' -d '{ "text": "Many countries currently have an assembly named a senate, composed of senators who may be elected, appointed, have inherited the title, or gained membership by other methods, depending on the country." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc02?pretty=true' -d '{ "text": "In Germany, the last Senate of a State parliament, the Senate of Bavaria, was abolished in 1999." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc03?pretty=true' -d '{ "text": "The economy is fueled by an abundance of natural resources and a high worker productivity." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc04?pretty=true' -d '{ "text": "The atoms of metallic substances are closely positioned to neighboring atoms in one of two common arrangements." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc05?pretty=true' -d '{ "text": "Atoms of metals readily lose their outer shell electrons, resulting in a free flowing cloud of electrons within their otherwise solid arrangement." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc06?pretty=true' -d '{ "text": "Metals in general have high electrical conductivity, high thermal conductivity, and high density. Typically they are malleable and ductile, deforming under stress without cleaving." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc07?pretty=true' -d '{ "text": "Mechanical properties of metals include ductility, i.e. their capacity for plastic deformation. Reversible elastic deformation in metals can be described by Hookes Law for restoring forces, where the stress is linearly proportional to the strain." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc08?pretty=true' -d '{ "text": "An alloy is a mixture of two or more elements in which the main component is a metal. Most pure metals are either too soft, brittle or chemically reactive for practical use." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc09?pretty=true' -d '{ "text": "The strength of metallic bonds for different metals reaches a maximum around the center of the transition metal series, as those elements have large amounts of delocalized electrons in tight binding type metallic bonds." }'
curl -XPUT 'http://localhost:9200/testindex/testdoc/doc10?pretty=true' -d '{ "text": "A parliament is a legislature. More generally, \"parliament\" may simply refer to a democratic governments legislature." }'
curl -XPOST 'http://localhost:9200/testindex/_refresh?pretty=true'
# This works in ES 1.1.0:
curl -XPOST 'http://localhost:9200/testindex/testdoc/_search?pretty=true' -d '
{
"size": 0,
"query": {
"term": {
"testdoc.text": {
"value": "metals"
}
}
},
"aggregations": {
"contentTerms": {
"significant_terms": {
"field": "text"
}
}
}
}'
# This leads to an NPE at o.e.s.aggregations.bucket.significant.
# SignificantTermsAggregatorFactory.getBackgroundFrequency(SignificantTermsAggregatorFactory.java:190)
# in ES 1.1.0 and to "Infinity" scores in master:
curl -XPOST 'http://localhost:9200/testindex/testdoc/_search?pretty=true' -d '
{
"size": 0,
"query": {
"term": {
"testdoc.text": {
"value": "metals"
}
}
},
"aggregations": {
"contentTerms": {
"significant_terms": {
"field": "testdoc.text"
}
}
}
}'
##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment