Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 6.04 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Elasticsearch: excluding filters while faceting possible? (like in Solr)
  2. curl -XPUT 'http://127.0.0.1:9200/my_index/?pretty=1'  -d '
  3. {
  4.    "mappings" : {
  5.       "product" : {
  6.          "properties" : {
  7.             "product_type" : {
  8.                "index" : "not_analyzed",
  9.                "type" : "string"
  10.             },
  11.             "product_name" : {
  12.                "type" : "string"
  13.             }
  14.          }
  15.       }
  16.    }
  17. }
  18. '
  19.        
  20. curl -XPUT 'http://127.0.0.1:9200/my_index/product/1?pretty=1'  -d '
  21. {
  22.    "product_type" : "A",
  23.    "product_name" : "foo bar"
  24. }
  25. '
  26. curl -XPUT 'http://127.0.0.1:9200/my_index/product/2?pretty=1'  -d '
  27. {
  28.    "product_type" : "B",
  29.    "product_name" : "foo bar"
  30. }
  31. '
  32. curl -XPUT 'http://127.0.0.1:9200/my_index/product/3?pretty=1'  -d '
  33. {
  34.    "product_type" : "C",
  35.    "product_name" : "bar"
  36. }
  37. '
  38.        
  39. curl -XGET 'http://127.0.0.1:9200/my_index/product/_search?pretty=1'  -d '
  40. {
  41.    "query" : {
  42.       "text" : {
  43.          "product_name" : "foo"
  44.       }
  45.    },
  46.    "filter" : {
  47.       "term" : {
  48.          "product_type" : "A"
  49.       }
  50.    },
  51.    "facets" : {
  52.       "product_type" : {
  53.          "terms" : {
  54.             "field" : "product_type"
  55.          }
  56.       }
  57.    }
  58. }
  59. '
  60.  
  61. # {
  62. #    "hits" : {
  63. #       "hits" : [
  64. #          {
  65. #             "_source" : {
  66. #                "product_type" : "A",
  67. #                "product_name" : "foo bar"
  68. #             },
  69. #             "_score" : 0.19178301,
  70. #             "_index" : "my_index",
  71. #             "_id" : "1",
  72. #             "_type" : "product"
  73. #          }
  74. #       ],
  75. #       "max_score" : 0.19178301,
  76. #       "total" : 1
  77. #    },
  78. #    "timed_out" : false,
  79. #    "_shards" : {
  80. #       "failed" : 0,
  81. #       "successful" : 5,
  82. #       "total" : 5
  83. #    },
  84. #    "facets" : {
  85. #       "product_type" : {
  86. #          "other" : 0,
  87. #          "terms" : [
  88. #             {
  89. #                "count" : 1,
  90. #                "term" : "B"
  91. #             },
  92. #             {
  93. #                "count" : 1,
  94. #                "term" : "A"
  95. #             }
  96. #          ],
  97. #          "missing" : 0,
  98. #          "_type" : "terms",
  99. #          "total" : 2
  100. #       }
  101. #    },
  102. #    "took" : 3
  103. # }
  104.        
  105. # [Wed Jan 18 17:15:09 2012] Protocol: http, Server: 192.168.5.10:9200
  106. curl -XGET 'http://127.0.0.1:9200/my_index/product/_search?pretty=1'  -d '
  107. {
  108.    "query" : {
  109.       "text" : {
  110.          "product_name" : "foo"
  111.       }
  112.    },
  113.    "filter" : {
  114.       "term" : {
  115.          "product_type" : "A"
  116.       }
  117.    },
  118.    "facets" : {
  119.       "product_type" : {
  120.          "global" : 1,
  121.          "terms" : {
  122.             "field" : "product_type"
  123.          }
  124.       }
  125.    }
  126. }
  127. '
  128.  
  129. # [Wed Jan 18 17:15:09 2012] Response:
  130. # {
  131. #    "hits" : {
  132. #       "hits" : [
  133. #          {
  134. #             "_source" : {
  135. #                "product_type" : "A",
  136. #                "product_name" : "foo bar"
  137. #             },
  138. #             "_score" : 0.19178301,
  139. #             "_index" : "my_index",
  140. #             "_id" : "1",
  141. #             "_type" : "product"
  142. #          }
  143. #       ],
  144. #       "max_score" : 0.19178301,
  145. #       "total" : 1
  146. #    },
  147. #    "timed_out" : false,
  148. #    "_shards" : {
  149. #       "failed" : 0,
  150. #       "successful" : 5,
  151. #       "total" : 5
  152. #    },
  153. #    "facets" : {
  154. #       "product_type" : {
  155. #          "other" : 0,
  156. #          "terms" : [
  157. #             {
  158. #                "count" : 1,
  159. #                "term" : "C"
  160. #             },
  161. #             {
  162. #                "count" : 1,
  163. #                "term" : "B"
  164. #             },
  165. #             {
  166. #                "count" : 1,
  167. #                "term" : "A"
  168. #             }
  169. #          ],
  170. #          "missing" : 0,
  171. #          "_type" : "terms",
  172. #          "total" : 3
  173. #       }
  174. #    },
  175. #    "took" : 4
  176. # }
  177.        
  178. curl -XPUT 'http://127.0.0.1:9200/my_index/?pretty=1'  -d '
  179. {
  180.    "mappings" : {
  181.       "product" : {
  182.          "properties" : {
  183.             "color" : {
  184.                "index" : "not_analyzed",
  185.                "type" : "string"
  186.             },
  187.             "name" : {
  188.                "type" : "string"
  189.             },
  190.             "type" : {
  191.                "index" : "not_analyzed",
  192.                "type" : "string"
  193.             }
  194.          }
  195.       }
  196.    }
  197. }
  198. '
  199.        
  200. curl -XPUT 'http://127.0.0.1:9200/my_index/product/1?pretty=1'  -d '
  201. {
  202.    "color" : "red",
  203.    "name" : "foo bar",
  204.    "type" : "A"
  205. }
  206. '
  207.  
  208. curl -XPUT 'http://127.0.0.1:9200/my_index/product/2?pretty=1'  -d '
  209. {
  210.    "color" : [
  211.       "red",
  212.       "blue"
  213.    ],
  214.    "name" : "foo bar",
  215.    "type" : "B"
  216. }
  217. '
  218.  
  219. curl -XPUT 'http://127.0.0.1:9200/my_index/product/3?pretty=1'  -d '
  220. {
  221.    "color" : [
  222.       "green",
  223.       "blue"
  224.    ],
  225.    "name" : "bar",
  226.    "type" : "C"
  227. }
  228. '
  229.        
  230. curl -XGET 'http://127.0.0.1:9200/my_index/product/_search?pretty=1'  -d '
  231. {
  232.    "filter" : {
  233.       "and" : [
  234.          {
  235.             "term" : {
  236.                "color" : "blue"
  237.             }
  238.          },
  239.          {
  240.             "term" : {
  241.                "type" : "A"
  242.             }
  243.          }
  244.       ]
  245.    },
  246.    "facets" : {
  247.       "color" : {
  248.          "terms" : {
  249.             "field" : "color"
  250.          },
  251.          "facet_filter" : {
  252.             "term" : {
  253.                "type" : "A"
  254.             }
  255.          }
  256.       },
  257.       "type" : {
  258.          "terms" : {
  259.             "field" : "type"
  260.          },
  261.          "facet_filter" : {
  262.             "term" : {
  263.                "color" : "blue"
  264.             }
  265.          }
  266.       }
  267.    }
  268. }
  269. '
  270.  
  271. # [Wed Jan 18 19:58:25 2012] Response:
  272. # {
  273. #    "hits" : {
  274. #       "hits" : [],
  275. #       "max_score" : null,
  276. #       "total" : 0
  277. #    },
  278. #    "timed_out" : false,
  279. #    "_shards" : {
  280. #       "failed" : 0,
  281. #       "successful" : 5,
  282. #       "total" : 5
  283. #    },
  284. #    "facets" : {
  285. #       "color" : {
  286. #          "other" : 0,
  287. #          "terms" : [
  288. #             {
  289. #                "count" : 1,
  290. #                "term" : "red"
  291. #             }
  292. #          ],
  293. #          "missing" : 0,
  294. #          "_type" : "terms",
  295. #          "total" : 1
  296. #       },
  297. #       "type" : {
  298. #          "other" : 0,
  299. #          "terms" : [
  300. #             {
  301. #                "count" : 1,
  302. #                "term" : "C"
  303. #             },
  304. #             {
  305. #                "count" : 1,
  306. #                "term" : "B"
  307. #             }
  308. #          ],
  309. #          "missing" : 0,
  310. #          "_type" : "terms",
  311. #          "total" : 2
  312. #       }
  313. #    },
  314. #    "took" : 3
  315. # }