2017-02-08 42 views
0

在Elasticsearch渗滤液指数我有一个指标:产品如何创建由多个字段

curl -XPUT "http://localhost:9200/products/product/1" -d' 
{ 
    "title": "Iphone 6", 
    "category_id": 4, 
    "price": 7788, 
    "owner_id": 21 
}' 

如何创建渗滤液指数为3个字段:标题,CATEGORY_ID,价格是多少?

Percolate Query这里我只找到了如何做1场。

回答

1

创建两个映射

curl -XPUT 'localhost:9200/percolate-index?pretty' -H 'Content-Type: application/json' -d' 
{ 
    "mappings": { 
     "doctype": { 
      "properties": { 
       "title": { 
        "type": "text" 
       }, 
       "category_id": { 
        "type": "long" 
       }, 
       "price": { 
        "type": "long" 
       } 
      } 
     }, 
     "queries": { 
      "properties": { 
       "query": { 
        "type": "percolator" 
       } 
      } 
     } 
    } 
}' 

指数在过滤器

curl -XPUT 'localhost:9200/percolate-index/queries/1?refresh&pretty' -H 'Content-Type: application/json' -d' 
{ 
    "query": { 
     "bool": { 
      "must": { 
       "multi_match": { 
        "query": "iphone", 
        "fields": ["title"] 
       } 
      }, 
      "filter": [ 
       { 
        "terms": { 
         "category_id": [4] 
        } 
       } 
      ] 
     } 
    } 
}' 

匹配的文件已注册的过滤器查询

curl -XGET 'localhost:9200/percolate-index/_search?pretty' -H 'Content-Type: application/json' -d' 
{ 
    "query" : { 
     "percolate" : { 
      "field" : "query", 
      "document_type" : "doctype", 
      "document" : { 
       "title" : "iphone 6", 
       "category_id" : 4 
      } 
     } 
    } 
}' 
注册查询
相关问题