Skip to content

Specifying multiple returnFields values #450

Description

@blowmage

In #442 @yyr2015 wrote:

Setting "returnFields=*" returns all fields in each document. Setting "returnFields=field1" returns only field1 in each document, and setting "returnFields=field1&returnFields=field2" returns field1 and field2 in each document.

We can not specify returnFields, and set returnFields to a single value, but cannot set returnFields to multiple values. Only the last value is returned. The following are the requests made to the Search API and their responses. The requests are all authenticated with signet.

No fields specified and no fields returned

https://cloudsearch.googleapis.com/v1/projects/nodal-almanac-725/indexes/test/search?query=ruby

{
  "results": [
    {
      "docId": "gcloud-ruby",
      "nextPageToken": "..."
    }
  ],
  "matchedCount": "1"
}

All fields specified (using "*") and all fields returned

https://cloudsearch.googleapis.com/v1/projects/nodal-almanac-725/indexes/test/search?query=ruby&returnFields=%2A

{
  "results": [
    {
      "docId": "gcloud-ruby",
      "fields": {
        "summary": {
          "values": [
            {
              "stringValue": "Idiomatic Ruby client for Google Cloud Platform services.",
              "stringFormat": "TEXT"
            }
          ]
        },
        "title": {
          "values": [
            {
              "stringValue": "gcloud-ruby",
              "stringFormat": "TEXT"
            }
          ]
        },
        "description": {
          "values": [
            {
              "stringValue": "Gcloud is the official library for interacting with Google Cloud.",
              "stringFormat": "TEXT"
            }
          ]
        }
      },
      "nextPageToken": "..."
    }
  ],
  "matchedCount": "1"
}

One field specified ("title") and one field returned

https://cloudsearch.googleapis.com/v1/projects/nodal-almanac-725/indexes/test/search?query=ruby&returnFields=title

{
  "results": [
    {
      "docId": "gcloud-ruby",
      "fields": {
        "title": {
          "values": [
            {
              "stringValue": "gcloud-ruby",
              "stringFormat": "TEXT"
            }
          ]
        }
      },
      "nextPageToken": "..."
    }
  ],
  "matchedCount": "1"
}

Two fields specified ("title" and "description") but only one field ("description") returned

https://cloudsearch.googleapis.com/v1/projects/nodal-almanac-725/indexes/test/search?query=ruby&returnFields=title&returnFields=description

{
  "results": [
    {
      "docId": "gcloud-ruby",
      "fields": {
        "description": {
          "values": [
            {
              "stringValue": "Gcloud is the official library for interacting with Google Cloud.",
              "stringFormat": "TEXT"
            }
          ]
        }
      },
      "nextPageToken": "..."
    }
  ],
  "matchedCount": "1"
}

Three fields specified ("title", "description", "summary") but only one field ("summary") returned

https://cloudsearch.googleapis.com/v1/projects/nodal-almanac-725/indexes/test/search?query=ruby&returnFields=title&returnFields=description&returnFields=summary

{
  "results": [
    {
      "docId": "gcloud-ruby",
      "fields": {
        "summary": {
          "values": [
            {
              "stringValue": "Idiomatic Ruby client for Google Cloud Platform services.",
              "stringFormat": "TEXT"
            }
          ]
        }
      },
      "nextPageToken": "..."
    }
  ],
  "matchedCount": "1"
}

(The nextPageToken values have been truncated.)

/cc @chrisnb and @yyr2015

Activity

  1. blowmage commented on Dec 7, 2015

    @blowmage
    ContributorAuthor

    @yyr2015 @chrisnb Ping? Any update on this?

  2. yyr2015 commented on Dec 8, 2015

    @yyr2015

    I am not able to reproduce the problem. Can you please help try the following:

    In a new index, add a simple document with 2 or 3 fields, like the example in our document:

    {
        "docId": "doc1",
        "fields": {
            "field2": {
                "values": [{
                    "stringValue": "\u003chtml\u003ehelloworld\u003c/html\u003e",
                    "stringFormat": "HTML"
                }]
            },
            "field1": {
                "values": [{
                    "stringValue": "helloworld",
                    "stringFormat": "TEXT"
                }, {
                    "timestampValue": "2014-08-18T21:19:55.000Z"
                }, {
                    "numberValue": 10
                }, {
                    "geoValue": "+40.6894,-074.0447"
                }]
            }
        }
    }

    Then try the search query to return all fields, 1 field or multiple fields.

  3. blowmage commented on Dec 8, 2015

    @blowmage
    ContributorAuthor

    Hi Yirong.

    Then try the search query to return all fields, 1 field or multiple fields.

    That's what the URLs and responses are in the description of this issue. We have no fields specified and returned, "*" specified and all fields returned, and then one, two, and three fields specified but only one field returned. I just tried this again and I get the same behavior.

    Can you post the URL you are hitting, including the querystring, when specifying and returning multiple fields? We were told we need to use flat params, but perhaps we need to format the input differently? Only the last "returnFields" specified in the querystring is being returned from the search API. I would really like to see how you are specifying multiple "returnFields" values.

  4. yyr2015 commented on Dec 8, 2015

    @yyr2015

    Here is what I tried:

    1. index the document:

    https://cloudsearch.googleapis.com/v1/projects/yyr-testapp/indexes/test2/documents -d '{"docId": "gcloud-ruby", "fields": {"summary": {"values": [{"stringValue": "Idiomatic Ruby client for Google Cloud Platform services.", "stringFormat": "TEXT"}]}, "title": {"values": [{"stringValue": "gcloud-ruby", "stringFormat": "TEXT"}]}, "description": {"values": [{"stringValue": "Gcloud is the official library for interacting with Google Cloud.", "stringFormat": "TEXT"}]}}}'

    {
    "docId": "gcloud-ruby"
    }

    1. search without returning any field:

    https://cloudsearch.googleapis.com/v1/projects/yyr-testapp/indexes/test2/search?query=ruby

    {
    "results": [
    {
    "docId": "gcloud-ruby",
    "nextPageToken": "......"
    }
    ],
    "matchedCount": "1"
    }

    1. search with all fields returned:

    https://cloudsearch.googleapis.com/v1/projects/yyr-testapp/indexes/test2/search?query=ruby&returnFields=%2A

    {
    "results": [
    {
    "docId": "gcloud-ruby",
    "fields": {
    "summary": {
    "values": [
    {
    "stringValue": "Idiomatic Ruby client for Google Cloud Platform services.",
    "stringFormat": "TEXT"
    }
    ]
    },
    "title": {
    "values": [
    {
    "stringValue": "gcloud-ruby",
    "stringFormat": "TEXT"
    }
    ]
    },
    "description": {
    "values": [
    {
    "stringValue": "Gcloud is the official library for interacting with Google Cloud.",
    "stringFormat": "TEXT"
    }
    ]
    }
    },
    "nextPageToken": "......"
    }
    ],
    "matchedCount": "1"
    }

    1. search with only 1 field returned:

    https://cloudsearch.googleapis.com/v1/projects/yyr-testapp/indexes/test2/search?query=ruby&returnFields=title

    {
    "results": [
    {
    "docId": "gcloud-ruby",
    "fields": {
    "title": {
    "values": [
    {
    "stringValue": "gcloud-ruby",
    "stringFormat": "TEXT"
    }
    ]
    }
    },
    "nextPageToken": "......"
    }
    ],
    "matchedCount": "1"
    }

    1. search with 2 fields returned:

    https://cloudsearch.googleapis.com/v1/projects/yyr-testapp/indexes/test2/search?query=ruby&returnFields=title&returnFields=description

    {
    "results": [
    {
    "docId": "gcloud-ruby",
    "fields": {
    "title": {
    "values": [
    {
    "stringValue": "gcloud-ruby",
    "stringFormat": "TEXT"
    }
    ]
    },
    "description": {
    "values": [
    {
    "stringValue": "Gcloud is the official library for interacting with Google Cloud.",
    "stringFormat": "TEXT"
    }
    ]
    }
    },
    "nextPageToken": "......"
    }
    ],
    "matchedCount": "1"
    }

    1. search with 3 fields returned:

    https://cloudsearch.googleapis.com/v1/projects/yyr-testapp/indexes/test2/search?query=ruby&returnFields=title&returnFields=description&returnFields=summary

    {
    "results": [
    {
    "docId": "gcloud-ruby",
    "fields": {
    "summary": {
    "values": [
    {
    "stringValue": "Idiomatic Ruby client for Google Cloud Platform services.",
    "stringFormat": "TEXT"
    }
    ]
    },
    "title": {
    "values": [
    {
    "stringValue": "gcloud-ruby",
    "stringFormat": "TEXT"
    }
    ]
    },
    "description": {
    "values": [
    {
    "stringValue": "Gcloud is the official library for interacting with Google Cloud.",
    "stringFormat": "TEXT"
    }
    ]
    }
    },
    "nextPageToken": "......"
    }
    ],
    "matchedCount": "1"
    }

  5. stephenplusplus commented on Dec 9, 2015

    @stephenplusplus

    Confirmed this works (when applied to this test case: googleapis/google-cloud-node#1012)

  6. blowmage commented on Dec 9, 2015

    @blowmage
    ContributorAuthor

    Oh man, the following comment was supposed to be posted yesterday:

    Thank you very much! This is super helpful. Your querystrings match ours, so we must have something else going on in the request. We've tried the node and python libraries but they have other issues calling this as well.

    I have identified the cause for this in the gcloud-ruby code and will post a fix later today. Thank you very much for your help!

  7. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    and removed
    status: blockedResolving the issue is dependent on other work.
    on Dec 9, 2015
  8. stephenplusplus commented on Dec 9, 2015

    @stephenplusplus

    To add more thanks in the mix, thank you @blowmage for catching this in the first place, since Node also had problems making a proper request. 👊

  9. blowmage commented on Dec 9, 2015

    @blowmage
    ContributorAuthor

    @stephenplusplus I should have some updated acceptance tests that will use returnFields and fieldExpressions either later today or early tomorrow. Keep an eye on #448.

  10. added a commit that references this issue on Dec 9, 2015
    8bd0437
  11. added a commit that references this issue on Dec 11, 2015
    6e00fea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions