doxzrb8721 2014-01-24 16:34
浏览 108

Elasticsearch在URL查询和JSON POST上有不同的结果

I'm completing a search function on a big online webstore.

I have a problem with additional fields. When I try searching for some fields in browser, it works, but when posting a JSON using bool filter, it gives me 0 results (doesn't raise an error).

Basically: when I visit localhost:9200/search/items/_search?pretty=true&q=field-7:Diesel It works well, however, in JSON it doesn't.

I've been googling all day and couldn't find any help in ElasticSeach documents. What frustrates me even more is that some other fields in bool query work OK, but this one doesn't.

I don't have any mapping and ES works for me out of the box - querying on the "name" field works well, as well as any other field, as well as for this field too - but only inside browser.

I realise that querying ES over browser uses so called "query string query".

Anyway, here is an example JSON that I'm posting to ElasticSearch. (searching all items that have "golf mk5" in their name, which have diesel fuel type - by searching field-7).

  {
        "query": {
            "filtered": {
                "filter": {
                    "bool": {
                        "must_not": [
                            {
                                "term": {
                                    "sold": "1"
                                }
                            },
                            {
                                "term": {
                                    "user_id": "0"
                                }
                            }
                        ],
                        "must": [
                            {
                                "term": {
                                    "locked": "0"
                                }
                            },
                            {
                                "term": {
                                    "removed": "0"
                                }
                            },
                            {
                                "terms": {
                                    "field-7": [
                                        "Diesel"
                                    ]
                                }
                            }
                        ]
                    }
                },
                "query": {
                    "match": {
                        "name": {
                            "operator": "and",
                            "query": "+golf +Mk5"
                        }
                    }
                }
            }
        },

        "sort": [
            {
                "ordering": {
                    "price": "desc"
                }
            }
        ],
        "from": 0,
        "size": 24,
        "facets": {
            "category_count": {
                "terms": {
                    "field": "category_id",
                    "size": 20,
                    "order": "count"
                }
            },
            "price": {
                "statistical": {
                    "field": "price"
                }
            }
        }
    }
  • 写回答

1条回答 默认 最新

  • dstjh46606 2014-01-25 17:52
    关注

    Using a query_string-query, the text is analyzed. With the term-query (and -filter), it is not.

    Since you're not specifying a mapping, you'll get the standard-analyzer for string fields. It tokenizes, lowercases and removes stopwords.

    Thus, the term Diesel will be indexed as diesel. Your terms-filter is looking up the exact term Diesel, which is different.

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line