elasticsearch - 如何在 Elasticsearch 中按多个字段创建渗透索引

标签 elasticsearch elasticsearch-percolate

我有一个索引:产品

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

如何为 3 个字段创建过滤索引:title、category_id、price?

Percolate Query在这里我只找到了如何处理 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
            }
        }
    }
}'

关于elasticsearch - 如何在 Elasticsearch 中按多个字段创建渗透索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42110372/

相关文章:

elasticsearch - Elastic Search 必须 + 至少一个过滤器查询中的 SHOULD

elasticsearch - 在Elasticsearch过滤器索引中查找特定查询

Elasticsearch 上下文建议地理上下文 - 无需过滤即可提升?

c# - 如何使用 Elasticsearch Nest 在一次操作中按 ID 删除多个文档

elasticsearch - 在 elasticsearch 渗透响应中评分

elasticsearch - 在Elasticsearch中分页渗滤结果

java - elasticsearch渗透java api示例

docker - 在kubernetes中运行最新的Elasticsearch集群

Elasticsearch -pyspark : not getting specific fields from document (getting all fields) even after specifying with spark

elasticsearch - 在Elasticsearch中更新问题