constant-score-query.asciidoc 968 B

123456789101112131415161718192021222324252627282930313233343536
  1. [[query-dsl-constant-score-query]]
  2. === Constant Score Query
  3. A query that wraps a filter or another query and simply returns a
  4. constant score equal to the query boost for every document in the
  5. filter. Maps to Lucene `ConstantScoreQuery`.
  6. [source,js]
  7. --------------------------------------------------
  8. {
  9. "constant_score" : {
  10. "filter" : {
  11. "term" : { "user" : "kimchy"}
  12. },
  13. "boost" : 1.2
  14. }
  15. }
  16. --------------------------------------------------
  17. The filter object can hold only filter elements, not queries. Filters
  18. can be much faster compared to queries since they don't perform any
  19. scoring, especially when they are cached.
  20. A query can also be wrapped in a `constant_score` query:
  21. [source,js]
  22. --------------------------------------------------
  23. {
  24. "constant_score" : {
  25. "query" : {
  26. "term" : { "user" : "kimchy"}
  27. },
  28. "boost" : 1.2
  29. }
  30. }
  31. --------------------------------------------------